3 ms·
Guard clauses are considered good practice in many languages, as opposed to nested if's. I'm not saying either approach is generally the right one, but I think
by bmicraft 3y ago
Guard clauses are considered good practice in many languages, as opposed to nested if's.
I'm not saying either approach is generally the right one, but I think it's interesting that best practice can be the polar opposite of his "single exit" recommendation
- drivers99 3y agoDijkstra came up with "guard". Well, "guarded command" as a formal part of the logic of correct programs: https://en.wikipedia.org/wiki/Guarded_Command_Language https://en.wikipedia.org/wiki/Guarded_Command_Language > The guard is a proposition, which must be true before the statement is executed. At the start of that statement's execution, one may assume the guard to be true. Also, if the guard is false, the statement will not be executed. The use of guarded commands makes it easier to prove the program meets the specification. The statement is often another guarded command.