Page 220 - DCAP305_PRINCIPLES_OF_SOFTWARE_ENGINEERING
P. 220
Principles of Software Engineering
Notes • Comment anything that is not readily obvious in the code.
• To prevent recurring problems, always use comments on bug fixes and work-around code,
especially in a team environment.
• Use comments on code that consists of loops and logic branches. These are key areas that
will assist the reader when reading source code.
• Separate comments from comment delimiters with white space. Doing so will make
comments stand out and easier to locate when viewed without color clues.
• Throughout the application, construct comments using a uniform style, with consistent
punctuation and structure.
Format
Formatting makes the logical organization of the code stand out. Taking the time to ensure that
the source code is formatted in a consistent, logical manner is helpful to yourself and to other
developers who must decipher the source code.
Following are recommended formatting techniques:
• Establish a standard size for an indent, such as four spaces, and use it consistently. Align
sections of code using the prescribed indentation.
• Use a monospace font when publishing hard-copy versions of the source code.
• Except for constants, which are best expressed in all uppercase characters with underscores,
use mixed case instead of underscores to make names easier to read.
• Align open and close braces vertically where brace pairs align, such as:
for (i = 0; i < 100; i++)
{
…
}
You can also use a slanting style, where open braces appear at the end of the line and
close braces appear at the beginning of the line, such as:
for (i = 0; i < 100; i++)
{
…
}
Whichever style is chosen, use that style throughout the source code.
• Indent code along the lines of logical construction. Without indenting, code becomes
difficult to follow, such as:
If … Then
If … Then
…
Else
…
End If
Else
…
End If
214 LOVELY PROFESSIONAL UNIVERSITY