Live data from Hacker News

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

jesseduffield.com

41–50 of 326 posts

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

#41
post #13
post #5

The worst thing about `unless` and double negatives, is having been raised in a culture with different double negative rules than English. In Italian a double negative is still negative. I know boolean logic pretty well, but `unless !something` still trips me up to this day.

There are two different kinds of double negatives and English actually has both. E.g. `I can't get no satisfaction` is structurally equivalent to French `ne ... pas`, i.e the second `no` is a reaffirmation, not a negation. On the other hand `read this unless you're not a developer` is a logical double negation and thus equivalent to `read this if you're a developer`. In practice of course there are usually implied su…

> any true "double negative" in English that isn't indirect

A: Do you like your hometown?

B: Well, I don't not like my hometown

In boolean logic, not false is true, but in English there's often a middle ground. See also https://en.wikipedia.org/wiki/Law_of_excluded_middle

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

#43
In Common Lisp, there is `unless' and `when' but they don't allow `else' branch.

(when CONDITION BODY)

(unless CONDITION BODY)

The value of the statement is BODY or NIL if it wasn't executed.

I can't remember a time when it wasn't clear (though you can always build usage that are unclear).

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

#44
post #35

Earlier quoted context omitted.

It's not pointless, it makes code read better. It's another option to have. It's not meant for every use case. It indicates you don't understand Ruby if you find yourself using an "unless" in a complex boolean operation. It's meant for simple cases like an inline return statement return unless User.exists(id=100)

God that's such a landmine when reading code. Seeing a return without an explicit change of scope... Why ? To save one line ? Yep that's why I hate ruby - worked on one mature codebase for a year and after seeing various such gems used across the project - from >10 devs - I'm confident I will never touch the language again.

If you're returning who cares about the scope? Are you saying visually you'd like to have indentation inside the if body? If that's the case there is also nothing stopping you in most languages from doing something as nasty as:

  a=1;b=2;c=3;d=a+b==c?4:5;return d

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

#46
post #5

The worst thing about `unless` and double negatives, is having been raised in a culture with different double negative rules than English. In Italian a double negative is still negative. I know boolean logic pretty well, but `unless !something` still trips me up to this day.

> In Italian a double negative is still negative.

Same in Spanish!

I think you're making a very good point here – understanding "unless" (quickly, i.e. without having to think about it) very much depends on one's understanding of the English language and/or one's mother tongue. Sure, one can probably get used to it (like one gets used to what "if/else" means etc.), but it definitely increases the mental effort needed to read & understand code.

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

#47

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.

> It's the exact opposite of pythons "There should be one– and preferably only one –obvious way to do it"

    unless python.major_version > 1 
other zen of python's rules that did not live up the expectations

- beautiful is better than ugly => tell that to numpy or pandas

- readability counts => (¬з¬)

- if the implementation is hard to explain, it's a bad idea => then the World is full of very bad ideas

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

#50
post #35

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.

It's not pointless, it makes code read better. It's another option to have. It's not meant for every use case. It indicates you don't understand Ruby if you find yourself using an "unless" in a complex boolean operation. It's meant for simple cases like an inline return statement return unless User.exists(id=100)

I'll admit I'm not a Ruby developer, but wow it allows return conditionally inside an expression? What were the language designers thinking?! I can't think of any other language that allows return inside an expression (or break/continue). Let's see: C, C++, C#, Python, Javascript, Object Pascal, Java, Rust; all nope. That is indefensible.
Post reply on HN