Indentation refers to the spacing that occurs before a line begins in a source file, and is one part of an umbrella term, programming style: the personal or sometimes professional preferences of programmers (such as the habits of hobbyist programmers, or style guidelines used in the workplace) which make programming instructions more presentable or legible.
Our web site has no formal style guidelines; however, from a presentability and legibility standpoint, it is easier to maintain and read code that is carefully indented. At our site, we strongly encourage people to adopt some indentation standards for themselves so that they find using the message boards a more helpful and fleeting experience and are more prepared to work on projects with others.
Indentation as a Model of Consistency
As in writing, one style does not suit all the programmers in the world. Apart from expectations in the workspace, programmers will commonly differ on several points concerning indentation and programming style, mostly out of personal preference.
Most view indentation as a presentation model that simply needs consistency and consideration for the medium where the code will be printed or displayed. For instance, at cboard, we often see code indented with a mixture of tabs and spaces instead of picking one or the other and unintentionally causing it to be formatted improperly by browsers in a fixed-width font. For this reason, it should be considered an unspoken rule that on forums and other virtual mediums, spaces rule, whereas tabs may rule in the realm of IDEs or the printed medium.
Achieving consistency is easy if you choose to adopt an already existing style such as K&R or Allman style, however, programmers sometimes develop their own tastes and opinions about what “looks good” through programming experience. Common considerations in the format of any style guideline are:
- placement of braces and parenthesis
- spacing between operators
- tab length (or the sum of the spaces from the beginning of a line)
- the arrangement and format of comment lines
Individuals may find it rewarding to rotate their indentation styles to keep their work from getting repetitive or simply getting used to a style they may be expected to use more commonly. It is equally imprortant to avoid deviating from the style, and to never rotate styles in the middle of a source file or project, where the indentation may become a distraction.