Read this post ‘unless’ you’re not a Ruby developer
jesseduffield.com
Read this post ‘unless’ you’re not a Ruby developer
1–10 of 326 posts
Re: Read this post ‘unless’ you’re not a Ruby developer
#2Re: Read this post ‘unless’ you’re not a Ruby developer
#3I had to read the title five times to decide if I was supposed to read it. I'm sold.
Re: Read this post ‘unless’ you’re not a Ruby developer
#4However I find some of the examples / justifications unfortunate e.g.
> I find the second option less readable because it suggests that raising the error would be the normal thing to do, when in fact it’s the exceptional thing to do.
It’s not tho. The normal thing to do is to reject access, being an admin is exceptional. A restricted endpoint should absolutely assume the user is not authorised.
Re: Read this post ‘unless’ you’re not a Ruby developer
#5I know boolean logic pretty well, but `unless !something` still trips me up to this day.
Re: Read this post ‘unless’ you’re not a Ruby developer
#6I had to read the title five times to decide if I was supposed to read it. I'm sold.
I’m one of those weirdos who can inline a double negative instantly so, I didn’t read it yet but I probably will because I’m curious about the title anyway
Re: Read this post ‘unless’ you’re not a Ruby developer
#7I don’t disagree with the essay, and I do generally dislike “unless” as it’s a cutesy statement which does not pull its weight (it would probably be better if there was no “else” clause at all). However I find some of the examples / justifications unfortunate e.g. > I find the second option less readable because it suggests that raising the error would be the normal thing to do, when in fact it’s the exceptional thin…
Re: Read this post ‘unless’ you’re not a Ruby developer
#8Re: Read this post ‘unless’ you’re not a Ruby developer
#9It's the exact opposite of pythons "There should be one– and preferably only one –obvious way to do it" - they intentionally create solutions that have zero practical benefit - it's just fuels arguments based on preferences and introduces mental overhead due to inconsistency.
Re: Read this post ‘unless’ you’re not a Ruby developer
#10 send_email if !user.suspended?
or send_email if luser.suspended?
The latter could easily be an aggressive dev sending abusive emails to users they dislike enough to call lusers, at first glance at least ...