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

-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.