#guardClauses

🍄🌈🎮💻🚲🥓🎃💀🏴🛻🇺🇸schizanon@mas.to
2023-06-28

I think that the `if` block of an if/else statement should check for positive "happy path" conditions and the else blocks should handle exceptions.

bad:

if (!isExpected) handleUnexpected();
else handleExpected();

good:

if (isExpected) handleExpected();
else handleUnexpected();

Especially if you drop the `else`; like with #guardClauses or #earlyReturns.

It makes the #code harder to read and fold in the IDE; saving a level of indentation is not worth it!

#javaScript #programming #webDev

2022-10-11

Nesting "If Statements" Is Bad. Do This Instead. #GuardClauses #coding #programming
youtube.com/shorts/Zmx0Ou5TNJs

linuxwebdevelopment.comlinuxwebdevelopment
2021-04-03
Ænðr E. Feldstrawaeveltstra
2019-07-12

Unless the recognizes declarative predicates and flattens them into if-then-else structures (which turn into if-goto assembler), this could lead to a huge stack full of procedures that are just idling about, waiting for a nested procedure to get released.

It's the exact opposite of which short-circuit execution by failing fast, and return to their caller quickly, freeing that stack frame instantly.

Client Info

Server: https://mastodon.social
Version: 2025.04
Repository: https://github.com/cyevgeniy/lmst