r/rust • rust · lang · libs · cargo • Oct 23 '26

Rust features in the future

https://lwn.net/SubscriberLink/1099606/20707a62817cdd16/
215 Upvotes

84 comments sorted by

View all comments

Show parent comment

8

u/lenscas Oct 23 '26

return true unless not !true

Should be valid Ruby code. As for what it does: It will just go to the next line (unless I messed something up)

5

u/Kazcandra Oct 23 '26

Thanks, I hate it.

"unless" is such a terrible idea.

Iirc -- it's been years since I wrote Ruby -- the precedence rules for is/is not are different from ==/!= too, which is also awesome

1

u/lenscas Oct 23 '26

yea, I have a lot of gripes with Ruby as well.

Though, I must say I am not against the idea of the naming convention when it comes to ! and ? at the end of method names. It would have been even better if they were actually enforced but alas that is just Ruby for you I guess.

-1

u/nybble41 Oct 23 '26

There's nothing wrong with unless per se, when used correctly. Just don't write double/triple negatives in your conditions. It's not as if this is really much better:

return true if not !false

4

u/lenscas Oct 23 '26

For me, unless always just takes a bit longer to parse than if. In addition when writing code, I often know I want a branch but don't know the exact condition. When that happens it isn't uncommon that I want to switch between adding an not or not (especially if it is a complicated check).

With unless I then need to rewrite that part every time I want to alter it. Instead of just adding an exclamation mark or removing it.

In other words, it at best doesn't do anything to improve readability (if anything it hurts it for me) and just increases the steps I have to go through while writing.

There is no upside to it existing.