← Back to context

Comment by jcmoyer

2 days ago

> logical operators do not short-circuit (so both sides of an or will execute even if the left side is true)

There are two syntaxes: `and` which doesn't short circuit, and `and then` which does. Ditto for `or` and `or else`.

Interestingly Rust uses the same convention for some methods: Option has "and_then", "or_else", and also a distinction between "unwrap_or" and "unwrap_or_else".

Coincidentally, this is the same as C and C++: you have & and && and then you have | and ||. We think of & and | as something that's only useful for bit twiddling, but when you apply them to boolean values, the semantics are exactly that of a non-short-circuiting boolean operator.