Defining Programming Standards   
for Professional Programmers 
  

         

Home

Contents

1: Standards

2: Psychological Factors

3: General Principles

4: Commenting

5: Naming

6: Code Layout

7: File Layout

8: Language Usage

9: Data Usage

10: Programming Usage

11: Implementing Standards

A: Example Standard

B: References

C: Glossary

Syque

About

Share this page:

Google
C Style
syque.com
Web

 

 

Books and
more at:

USA:

In association with amazon.com

UK:

In Association with Amazon.co.uk

Canada:

In Association with amazon.ca

 

 

CHAPTER 6 : Layout

PART 3 : LAYOUT

CHAPTER 6 : Code Layout
6.1 Basic principles of code layout
6.2 Use of Spaces
6.3 Use of blank lines
6.4 Use vertical alignment
6.5 Indentation level
6.6 Line wrapping
6.7 Braces
6.8 Use of parentheses
6.9 Nested single statement
6.10 Empty statements
6.11 'else..if'
6.12 'switch' statements
6.13 'do..while'
6.14 Labels
6.15 Data declarations
6.16 Function declaration
6.17 Preprocessor commands
6.18 Summary

<--Prev page | Next page -->

 

6.3  Use of blank lines

Spaces are used within a line to make individual items more readable, and to indicate the degree of association. Blank lines can be similarly used at the statement level to delimit larger chunks of information.

These 'Breathing points' in the code are often good points at which to put comments, summing up what has, or what is about to, happen. A blank line is itself, in effect, a comment. It says, "Stop, take a breath, look back at what you just read. Did you understand it? Do you need to read it again? Look forwards, can you see the next breathing point? Prepare to take in the next chunk":

 

MovePaperUp( CharHeight );
MoveCarriage( C_LEFT );      /* end of chunk 1 */

GetLine( LineBuf );          /* start of chunk 2 */
PrintLine( LineBuf );

 

Statements naturally tend to come in small chunks. If the chunk is large (ie. more than about 7 lines), then you should be looking for points at which to insert blank lines and/or comments.

The disadvantage of blank lines is that they increase the vertical size of the function, which means that there is less code visible at one time on the screen or page, which in turn means that it may be less easy to scan back (e.g. to find a variable).

 

<--Prev page | Next page -->

 

 

  © Syque 1995-2010

Massive Content -- Maximum Speed