Friday, May 20, 2011

Code Complete by Steve McConnell : Chapter 16

The author discusses unusual control structures in this chapter. The author first provides the information about debate going on for the use of goto statements in structured programming languages. The author then provides different ways to rewrite the code in such a way that goto statements are not required:

  • Rewrite with nested if statements
  • Rewrite with a status variable
The author then provides guidelines for using return statement:
  • Minimize the number of return statements
  • Use a return when it enhances readability
The author then discusses the use of recursion and provides following guidelines:
  • Make sure the recursion stops
  • Use safety counters to avoid infinite recursion
  • Limit recursion to one routine
  • Keep the usage of stack in check
  • Don't use recursion for Fibonacci or factorial calculation

No comments:

Post a Comment