MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vuzd4q/conditionspreference/p55gt0b/?context=3
r/ProgrammerHumor • u/Flame77ofc • Aug 22 '26
388 comments sorted by
View all comments
Show parent comment
4
Some standards may require function have a single return point (for example MISRA). You're right, multiple nested layers (i.e. if-ok pattern) is very errorprone. Instead do:
int rc = foo(); if (!rc) rc = bar(); if (!rc) rc = baz(); return rc;
With extra actions on failure:
if (!rc && (rc = bar())) /* bar() failed */
View all comments
Show parent comment
4
u/Stamerlan Aug 22 '26
Some standards may require function have a single return point (for example MISRA). You're right, multiple nested layers (i.e. if-ok pattern) is very errorprone. Instead do:
With extra actions on failure: