Skip to main content Accessibility help
×
Hostname: page-component-77c89778f8-fv566 Total loading time: 0 Render date: 2024-07-21T19:28:54.967Z Has data issue: false hasContentIssue false

2 - Formatting

Published online by Cambridge University Press:  03 May 2011

Get access

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
Publisher: Cambridge University Press
Print publication year: 2010

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

Save book to Kindle

To save this book to your Kindle, first ensure coreplatform@cambridge.org is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.

Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.

Find out more about the Kindle Personal Document Service.

  • Formatting
  • Richard K. Johnson
  • Book: The Elements of MATLAB Style
  • Online publication: 03 May 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511842290.004
Available formats
×

Save book to Dropbox

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.

  • Formatting
  • Richard K. Johnson
  • Book: The Elements of MATLAB Style
  • Online publication: 03 May 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511842290.004
Available formats
×

Save book to Google Drive

To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.

  • Formatting
  • Richard K. Johnson
  • Book: The Elements of MATLAB Style
  • Online publication: 03 May 2011
  • Chapter DOI: https://doi.org/10.1017/CBO9780511842290.004
Available formats
×