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,…
Read this post ‘unless’ you’re not a Ruby developer
221–230 of 326 posts
Re: Read this post ‘unless’ you’re not a Ruby developer
#222Earlier 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,…
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
#223Earlier 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.
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
#224Earlier 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?
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
#225I'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…
Re: Read this post ‘unless’ you’re not a Ruby developer
#226I'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…
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
#227Earlier 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…
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
#228Earlier 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…
Re: Read this post ‘unless’ you’re not a Ruby developer
#229Earlier 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?
Re: Read this post ‘unless’ you’re not a Ruby developer
#230I'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.