Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

"guard" is kind of useless but it's minor.


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


Perl's "unless" syntax, or allowing "if"s at the end of a statement, also solve this and are more flexible.


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




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: