I think more languages should have `unless`. I have seen lots of code like `if !(this || that)` that would be easier to read with `unless`. Sometimes `if !this && !this` is clear enough but I frequently find that I am decided between two mediocre options. I think the clarity of `unless`outweighs the benefit of another keyword, especially when it is so similar to `if`.

@kevincox Then again, `unless this or that` is really difficult to read. Does it mean `if !this and !that` or `if !this and that`?

@da Personally I find it very hard to read `unless a or b` as `(unless a) and (if b)`. In fact my head is hurting a bit trying to figure out how you parsed that sentence 😅

@kevincox `if !(this || that)` vs `if !this || that`. Does `unless` make a set of conditional statements negative or just the first condition in the statement. :thinksphere:

@da I would expect it to apply to the whole condition. I don't think the other way makes sense in order of precedence. You couldn't write `(if !a) && b { ... }` so I wouldn't expect unless to work like that.

In languages with () around the condition it is even more obvious as it would be `unless (a || b)`

@kevincox switch / case / default pattern, and discrete tests for 'this' and 'that' ending with else or explicit goto, make a natural place for the code to flow to if none already matched.

@kevincox People hated Perl because it told them the truth.

Waiting for BASIC's REPEAT...UNTIL to return. It's the inverse of do {} while!

@LionsPhil I'm also in favour of until loops. However with most modern languages supporting a for-each construct I don't need it as much as until.

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!