Saturday, March 19, 2011

Code Complete by Steve McConnell : Chapter 8

The author recommends defining major data structures during requirements analysis and architecture phase.

The author then provides a data literacy test to identify what expertise the reader posses in understanding data structures. He also recommends reading some books if the reader is not an expert in data structures.

The author then enlists reasons to create own data types:
  • Make modifications easier in future
  • Avoid excessive information distribution
  • Increase Reliability
  • Compensate for language weaknesses
The author then provides guidelines for creating own data types:
  • Create types with problem domain names
  • Do not use predefined types (like int, float in C++) directly in the code except in type definitions
  • Never redefine predefined types since it can create confusion in the mind of reader
  • Define substitute types for portability
  • Create types using other created types
The author then provides some guidelines for variable declarations:
  • Use a template for variable declaration
  • Turn of implicit declarations
  • Use naming conventions
The author emphasizes the importance of data initialization. Improper initialization can result from several situations:
  • A variable is never initialized
  • A variable's value is outdated
  • Only a part of the variable is assigned a value
The author then provides some guidelines for data initializations:
  • Check input parameters for validity
  • Initialize each variable close to where it is used
  • Check the need for reinitialization
  • Initialize named constants once, initialize variables with executable code
  • Initialize each variable as it's declared
  • Use compiler setting to initialize all variables
  • Use compiler warnings for uninitialized variables
  • Use a memory access checker to check for bad pointers
  • Initialize working memory at the beginning of the program

No comments:

Post a Comment