You are here

Vertical Alignment

5 February, 2015 - 11:20

You see this within the documentation area. All of the items are aligned up within the same column. This vertical alignment occurs again when the variables are defined. When declaring variable or constants many textbooks put several items on one line; like this:

Example 6.5: Common Textbook Defning of Variables

float length, width, height, price gal paint, total area, total cost; int coverage gal paint, total gal paint; 

However common this is in textbooks, it would generally not be acceptable to standards used in most companies. You should declare each item on its own line; like this:

Example 6.6: Proper Defning of Variables with Vertical Alignment

float length;float width;float height;float price_gal_paint;int coverage_gal_paint;float total_area;int total_gal_paint;float total_cost;

This method of using one item per line is more readable by humans. It is quicker to find an identifier name, because you can read the list vertically faster than searching horizontally. Some programmers list them in alphabetic order, especially when the number of variables exceeds about twenty.

The lines of code inside either function are also aligned vertically and indented two spaces from the left. The indentation helps set the block of visually.