Live data from Hacker News

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

jesseduffield.com

151–160 of 326 posts

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

#151

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…

Came here to say this. If you don't like it, don't use it, but it sure does seem to make things easier for other developers (Ruby and not-Ruby-but-assigned-to-this project) to understand. I like it.

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

#152

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…

"if" is almost always easier to reason with, "unless" can be elegant, but it's so often misused that it doesn't really matter

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

#153

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.

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, in my opinion. 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.

English has many words that I wouldn't consider elegant, simply because they're uncommon or convoluted. Never use a 10 dollar word when a 5 cent word will do.

So, if, like me and the ruby community, you prefer to optimize for developer happiness, "unless" is an elegant choice.

If you prefer to optimize for peak computing performance, if may be more computationally efficient use "if not".

But, _unless_ you're saying that you never use the word "unless" in everyday language, I think we can agree it's a good word that has good applications. I don't see why that wouldn't be true in programming.

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

#154

I really don’t understand the author’s point about adding extra conditions. They admit that many people will find a single condition with `unless` more readable. They then complain that it becomes unreadable when adding another condition. OK, so swap it out for an `if` at that point. No one is forcing you to keep using `unless` if the requirements change. “You should use a suboptimal solution to cater for unknown fut…

Indeed. I personally never fail to avoid not using "unless", unless there isn't a lack of extra conditions such that not refraining from instead using "if" wouldn't avoid not being less clear.

I'm not sure that making this sentence as obtuse as possible is a great idea to convey your point.

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

#155

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…

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

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

#156

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…

"if" is almost always easier to reason with, "unless" can be elegant, but it's so often misused that it doesn't really matter

I agree entirely that it can be misused. I'm not sure how often it's misused versus used properly. But I don't see why I should give up a useful logic tool just because others don't know how to use it well?

Let me put it this way: Are there _any_ programming paradigms that don't get poorly used? We need to learn how to use our tools well, not reduce them to banality.

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

#157
post #133

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 treat the 'if' statement and the '!ruby_dev' conditional as separate entities. That allows thinking of the conditional alone in boolean logic terms, instead of having to consider the outside prefix statement too. Therefore, coming from a computer science background I don't like 'unless'.

I could see that. Maybe it really is because I'm more of a writer than a computer scientist.

(For context: I dropped out of comp sci and took a job as a web dev ~18 years ago. Never looked back. But have ended up learning more about copywriting and marketing than computer science along the way.)

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

#158
When I write ruby, and I love ruby, I don't do too much condition branching of logic.

    - `if` and `unless` are for guards. The meat of every method, (the happy path) is at the bottom of that method.
    - If there are legitimately two options that branch on a conditional, I try to make sure that both branches return the same type. (feature flags, a/b feature testing, etc.)
    - If I can refactor code to a case statement, I will 95% of the time
This article screams, "I don't use a linter" or "I work at a company that doesn't have a style guide."

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

#159

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.

It's Ruby though, where Array has "size", "length", and "count", all of which are equivalent. The programmer chooses which one they prefer based on the context or their style or the phase of the moon.

Ruby inherits the Perl philosophy of "There's more than one way to do it". Compare with Python, and its "There should be one — and preferably only one — obvious way to do it."

It's true that it makes the compiler less elegant, but Ruby optimizes for the programmer at the expense of the compiler.

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

#160

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.

Negation makes code harder to read and understand.
Post reply on HN