Live data from Hacker News

Read this post ‘unless’ you’re not a Ruby developer

jesseduffield.com

321–326 of 326 posts

Re: Read this post ‘unless’ you’re not a Ruby developer

#321

Earlier quoted context omitted.

I feel like I have read if statements so many times that I have fast pattern matching circuits in my brain for them. When I come across an `unless`, I can't use them; I have to come back out into "conscious reading" mode, or something like that. Makes me crazy.

I'm a recovering rubyist (actually I still love ruby, just never get to write it anymore). The only times I felt `unless` was truly more readable than `if !something` was when it was used in the conditional suffix form like do_something unless already_done?

do_something if not already_done?

Problem with so much syntactic sugar is you need to retain/recall the semantics of the vocabulary. As a polyglot programmer who doesn't write much code anymore, it slows me down.

Re: Read this post ‘unless’ you’re not a Ruby developer

#322
post #289

Earlier quoted context omitted.

I have problems with 'unless' even in plain English text. I'm pretty good at English, I live in the USA, but I was not born here and my native language does not have a word for 'unless' (you have to use 3 words to express that idea!). I love Ruby, but the 'if' variation always get immediately parsed by my brain, while the 'unless' variation requires many seconds of thinking.

How about if you could write except if instead of unless ?

Nothing will ever come close to "if not" due to the decades of experience I have reading it everywhere.

Re: Read this post ‘unless’ you’re not a Ruby developer

#323
post #304
post #239

Earlier quoted context omitted.

Hm, I have the exact opposite interpretation. This is exactly the kind of feature that leads to arguments. If `unless` didn't exist, what argument could people be having about using `if !`? In a shared codebase, I think there should be as few (equally effective) ways to express an idea as possible. (Obviously there can be more- and less-efficient ways to write a function; I'm referring only to style.) The more arbitr…

> In a shared codebase, I think there should be as few (equally effective) ways to express an idea as possible...The more arbitrary choices people have, the more time is wasted on choosing one. I highly disagree! In my experience, forcing arbitrary style leads to so much more time wasted as people debate exactly which styles to enforce. > But in a shared codebase, developers writing in different styles is a net negat…

Fair enough, I understand every team is different.

> forcing arbitrary style leads to so much more time wasted as people debate exactly which styles to enforce

If this is happening often, I would unambiguously call that a problem, though. It should only happen once (and then, when enough has changed in the frameworks, maybe once again). This is exactly the philosophy Prettier takes: it is purposely difficult to change. It works really well as it is, and keeping it constantly optimized for community preference would be an anti-pattern.

> I disagree with this too. I have never found this type of style to be something that actually impacts readability and quality. If you using `if !` and I using `unless` is the problem with the codebase, that's not so bad.

I more or less actually agree with you on this. Small stylistic differences are generally negligible. But variations add up, and some are more egregious than others. I consider this more of a guiding philosophy than a rule; `if!` vs `unless` on its own is not a real problem.

Re: Read this post ‘unless’ you’re not a Ruby developer

#324

I don't have a problem with double negation but I hate ruby for this kind of design - pointless aliases for everything. It'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.

In Perl I once saw someone write; unless predicate do this else unless impossible_thing do the impossible What it did at runtime I have no idea, but it broke my brain for the rest of the week.

there is no else unless (or even elsunless, since this isn't javascript) in Perl, might have been

    unless (predicate) {
       do_this;
    } else {
       do_the_impossible unless impossible_thing;
    }

Re: Read this post ‘unless’ you’re not a Ruby developer

#326
post #251

Earlier quoted context omitted.

die "Port numbers below 1024 are forbidden" if $port is hardly unreadable spaghetti code.

Okay. Now compare: die "You may only use port numbers 1024 and higher" unless $port >= 1024 || is_root(current_uid()); die "Port numbers 1024 are forbidden" if $port

My head hurts! Does unless apply to both branches or just one. The if example is easier for sure.
Post reply on HN