Summary
Graphic designers have long known that the appropriate use of space around and within text can enhance the reading experience. Use layout, white space, and visual organization to clarify relationships and avoid straining the reader's short-term memory. When you modify your code, preserve layout and spacing to make sure that its format is correct. Code that is easy to scan and read is more likely to be correct.
Layout
The purpose of layout is to help the reader understand the code. It should accurately and consistently represent the logical structure of the code. Indentation is particularly helpful for revealing code structure and patterns to provide context for individual statements.
Keep Content Within the First Eighty Columns
Avoid writing code in long lines. Short lines are easier to read than long ones. In general, the readability of text decreases as column width increases. The recommended eighty-column width is a common dimension for editors, terminal emulators, printers, and debuggers.
Readability improves if unintentional line breaks and horizontal scrolling are avoided when passing a file between programmers. Limiting lines to eighty columns also makes side-by-side viewing in two windows easier.
Split Long Code Lines at Graceful Points
A long line is one that exceeds the suggested eighty-column limit. If you have two or more statements on one line, then write each on a line of its own.
- Type
- Chapter
- Information
- The Elements of MATLAB Style , pp. 7 - 17Publisher: Cambridge University PressPrint publication year: 2010