3 ms·
`guard` has its time and place, which is to refactor pyramids of doom away. The number of nested `if let` statements I've seen, and written, is upsetting.
by zapzupnz 4y ago
`guard` has its time and place, which is to refactor pyramids of doom away. The number of nested `if let` statements I've seen, and written, is upsetting.
- astrange 4y agoPerl'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.