2 ms·
Perl's "unless" syntax, or allowing "if"s at the end of a statement, also solve this and are more flexible.
by astrange 4y ago
Perl's "unless" syntax, or allowing "if"s at the end of a statement, also solve this and are more flexible.
- zapzupnz 4y agoI don't think they quite address the same thing. `guard` isn't just an `if` statement that looks for the negative of a Boolean; it also forces handing control flow out of scope in a consistent way — you cannot write a `guard` statement without also deciding how you'll exit the scope if the Boolean is false. The developer not being made to do so, and just embedding conditions within conditions, is how the pyramids of doom are constructed to begin with.