Key Points

  • For simple if-else statements, pay attention to the order of the if and else clauses, especially if they process a lot of errors. Make sure the nominal case is clear.

  • For if-then-else chains and case statements, choose an order that maximizes read-ability.

  • To trap errors, use the default clause in a case statement or the last else in a chain of if-then-else statements.

  • All control constructs are not created equal. Choose the control construct that's most appropriate for each section of code.

Get Code Complete, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.