The Psychology of Quality and More |
CHAPTER 6 : Layout
6.5 Indentation levelIndentation is another favorite topic for debate amongst programmers, with a wide range of preferences for the number of columns to leave between each nested level. The primary purpose of indenting is that the indented line is clearly visible from lines at other indent positions. Common indentation is anywhere between 2 and 8 characters per level.
Indent level = 2
for ( EmpNo = 0; EmpNo < EMP_NO_MAX; EmpNo++ )
An indent level of 2 helps the writer who is using only spaces, and not tabs, for indenting. It also allows more space on the line for statements, especially helping the use of long identifier names. The problem with a small indent size is that the lines are so close (column-wise) that it can be easy to confuse the indentation level (especially in a larger example than this).
Indent level = 4
for ( EmpNo = 0; EmpNo < EMP_NO_MAX; EmpNo++ ) ------------------------------------------------------------------- An indent level of 4 makes successive indent levels much clearer, whilst still allowing reasonable space for longer symbol names. However, if the default editor tabstop is 8 characters, and will not or cannot be reset, indenting becomes a clumsy combination of tabs and spaces. 4 characters is probably the most common indent level in use.
Indent level = 8
for ( EmpNo = 0; EmpNo < EMP_NO_MAX; EmpNo++ )
Indenting by 8 characters is convenient when this is the default tab position. The difference between indent levels is abundantly clear. However each additional nesting level does cause rapid tramping across towards the right hand screen boundary, particularly if long variable names are used. Nevertheless, this can be a blessing in disguise as it prompts a minimizing of deep nesting (which is a cause of additional complexity and consequent unreadability of the code).
|
Site Menu |
Quality: | Quality Toolbook | Tools of the Trade | Improvement Encyclopedia | Quality Articles | Being Creative | Being Persuasive | |
And: | C Style (Book) | Stories | Articles | Bookstore | My Photos | About | Contact | |
Settings: | Computer layout | Mobile layout | Small font | Medium font | Large font | Translate | |
You can buy books here |
And the big |