Live data from Hacker News

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

jesseduffield.com

221–230 of 326 posts

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

#221

Earlier quoted context omitted.

You've demonstrated that it is trivially replaced by 'if' and negation. I think that's almost the definition of inelegant.

Only if you definition of elegance is "please express yourself in as convoluted a way as possible, so as to minimize the number of words I need to know." The truth is there is a balance in all languages. Nearly every word was invented to prevent having to say a string of other words to mean the same thing. "Unless" is a single word to mean "If not". I consider that elegant. However, some languages take this too far,…

Unconscious clarity trumps literary fluidity when reading code.

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

#222

Earlier quoted context omitted.

You've demonstrated that it is trivially replaced by 'if' and negation. I think that's almost the definition of inelegant.

Only if you definition of elegance is "please express yourself in as convoluted a way as possible, so as to minimize the number of words I need to know." The truth is there is a balance in all languages. Nearly every word was invented to prevent having to say a string of other words to mean the same thing. "Unless" is a single word to mean "If not". I consider that elegant. However, some languages take this too far,…

> German famously has a word for nearly everything. I'm not sure that's elegant, in that it requires learning a far greater number of words.

That's not quite how it works though, right? Compound words are exactly that, combining two or more words to narrow down the meaning, without having to invent a new word. It's almost like "if not" vs "unless"...

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

#223
post #196

Earlier quoted context omitted.

Maybe these dangling conditionals are easier for you to read, but not for me. Were I reading through real-world code that did things like that: "OK, then we do this, and then we do that, and then-- Oh wait! Backtrack! We didn't do that thing at all! ... Now where were we, on our actual bug, before some very special person's syntactic speed bumps?"

But these are not absolutes. You can learn to use and read `unless` just as effortlessly as you did with `if`. I didn't learn to use/read `unless` on college. But I did focus on trying to learn these things and today I have another tool in my belt. It's an opportunity to get better at something versus banning it from usage because we aren't used to it. Growing is, for me, almost always the right choice.

Dangling conditionals the parent was talking about. Where the conditional comes after the thing you told it to do. Computationally, that's increased backtrack/lookahead for no good reason.

Regarding `unless`, that's a different matter. I was actually the person who proposed adding an `unless` syntax to Racket, and later regretted it. I was bikeshedding, before I knew something more useful to do.

This isn't about learning new things to add to our mental toolbox. This is about our difficulty to introspect on our own thought processes and effectiveness, and about bikeshedding.

Software engineering competence is hard, or we wouldn't have all the huge expenditures, slipped project schedules, and rampant security vulnerabilities. Redundant syntax forms that objectively makes it harder to read (see the lookahead and parser theory), solely because someone imagined it was sometimes easier to read this way (see dying languages Perl and Ruby) is just wasting our time, when we could be tackling the real problems.

(Though us pulling theories about programming and process out of our posteriors, to defend to the death, is arguably half our problem in industry right now.)

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

#224

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?

This is the poster child use case for "unless", IMHO.

Anything else (at least for me) is more difficult to read, it's probably due to being exposed to all thos other languages that do not have that syntactic construct. Using C syntax conditionals feels more natural to me, but again this is all opinionated.

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

#225

I'd consider myself a writer more than a developer, but I've been working in Rails for over 15 years, and one of my absolute favourite things is "unless". Why? Because it allows you to express yourself more elegantly. The click-bait title is misleading. It's meant to ridicule "unless", but actually achieves the opposite. If you were to write the title of the post as code, it would be: unless !ruby_dev read article en…

I agree with you. I think the complaints come down to "don't give people more confusing ways to write conditionals". And I agree with the complainers that it is easy to write conditionals in a confusing way, and that there are simply more confusing ways to write them when you can also use unless. But I think the problems come from not taking the time to make the conditional easy to parse, which is an issue whether or not you have unless. And it's not just trading if ! for unless (or if for unless !) -- sometimes it's "if valid" vs "unless !valid" vs "if !invalid" vs "unless invalid", depending whether it was easier to write the predicate for valid or for invalid. Even working in a language without unless, I frequently find myself encountering these difficulties, and I find that the only thing that helps is treating it like writing and deciding what logical progression will be the most helpful for the reader. What's most helpful for the reader won't always be to use unless, but sometimes it will, so it's nice to have the option.

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

#226

I'd consider myself a writer more than a developer, but I've been working in Rails for over 15 years, and one of my absolute favourite things is "unless". Why? Because it allows you to express yourself more elegantly. The click-bait title is misleading. It's meant to ridicule "unless", but actually achieves the opposite. If you were to write the title of the post as code, it would be: unless !ruby_dev read article en…

For me honestly it's one of the (many) things I dislike the most about Ruby.

Sure, I understand the "elegant" aspect, two symbols are shortened to one (although I'd argue that's not that important when it comes to clarity and legibility).

But every time I read "unless" in code it's quite jarring. I have to consciously translate it to "if not", and even then seeing the "unless" keeps tripping me off, perhaps because it's awkward in English to start a sentence out of the blue with "unless".

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

#227

Earlier quoted context omitted.

Negation makes code harder to read and understand.

Unless has negation built in. Which is why unless is such a hard concept for people to grasp, not just in code, but also in regular English. At least the "if not" makes the negation explicit, which can then be easily eliminated using several different techniques (early return, swap with the else condition) if the negation is confusing enough. However, "unless" necessarily includes negation because that's how the word…

> Which is why unless is such a hard concept for people to grasp, not just in code, but also in regular English.

This is the first I've heard about this confusion over the word "unless" in English.

In spoken English I do notice that most often the "unless" comes after a statement. Example: "I'll be there on time, unless the bus is late." That is more clear (to me) than "I'll be there on time, if the bus is not late." Maybe not by coincidence, I tend to like "unless" when it follows the action in in Ruby code, too.

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

#228
post #165

Earlier quoted context omitted.

You've demonstrated that it is trivially replaced by 'if' and negation. I think that's almost the definition of inelegant.

A for can be replaced by a while and a jump, that does not make it more or less elegant. IMHO, something ‶elegant″ in programming is not something that can't be built form something else (or we will all end up in writing only CMOVs), but something that conveys the meaning of its author precisely and concisely – which makes it inherently subjective. I'm in the `unless` team, I can perfectly understand if you are in th…

Note that I said 'trivially'. The structure and meaning of an 'unless' construction is the same as 'if', adding or removing only a negation. Using 'while' and a jump to construct a loop is much more expressively distant from 'for'.

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

#229

Earlier quoted context omitted.

unless is one of those things I have to read 2-3 times and it totally bogs me down.

Interesting! I wouldn't want to argue against your experience. I do wonder if it's an issue of "unless" being misused? Programmers using it just for fun rather than considering whether it's the best choice in context?

Also as a non-native English speaker, unless always makes me do a double take. It is not a word that naturally translates in my head, but that might just be me.

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

#230

I'd consider myself a writer more than a developer, but I've been working in Rails for over 15 years, and one of my absolute favourite things is "unless". Why? Because it allows you to express yourself more elegantly. The click-bait title is misleading. It's meant to ridicule "unless", but actually achieves the opposite. If you were to write the title of the post as code, it would be: unless !ruby_dev read article en…

You've demonstrated that it is trivially replaced by 'if' and negation. I think that's almost the definition of inelegant.

One of the hallmarks of Ruby is a full embrace of the notion of There's More Than One Way To Do It. Generations of developers around the world have seen this as being a core part of Ruby's elegance—at least to their minds (myself included).
Post reply on HN