Monday, August 31, 2015

Guidelines for using control structures(if/else if/Switch )

Important Note : program readability is most important after working software.

If statements :

  • Write nominal path through the code first ;then write the unusual cases last
  • Put the normal case after the if rather than the else
  • Try to consider the else clause 
If else if Statements :

  • Simplify the complicated condition checking with a function call
  • Keep the most common case first
  • Try to use switch/case statement instead of if else statements
Switch/Case statements :
  • Order cases alphabetically or numerically
  • Put the normal case first
  • Put the most frequently executed case first and the least executed cases last
  • Use default case for detecting legitimate defaults or errors

No comments:

Post a Comment