Effective Use of Space

Effective Use of Space

When you're writing code (including comments), you effectively have a blank canvas - blank space - in which to lay out your code/comments. When writing "for people first, computers second," your task is to most effectively lay out that code for human readers. Writing the best code requires making the most effective use of the available space on screen - both horizontal and vertical space.

Some coding standards mandate specific line-length limits. Humans indeed only have a field-of-view that is so wide, so there are limits to how long lines can be for a human to effectively read and comprehend them. However, with ever-increasing and varying computer monitor sizes and screen resolutions, it’s hard to enforce a one-size-fits-all line-length limit.

Regardless of whether your coding standards mandate a specific line-length limit or not, you still have a blank canvas of some size in which you can lay out comments. Some general guidelines to keep in mind include:

  • Keep consistent line-lengths within a given file, class, function, etc. (at the very least, be consistent within what can fit on screen at once).

  • Lines that are too short reduce the number of lines of code that can be on screen at once, making it harder to read/understand.

  • Lines that are too long make it harder to read/understand code by virtue of limitations in human field-of-view and what we can keep in our minds at once.

  • Blank lines of space are useful for readability, but you should rarely need more than 1 consecutive blank line (more reduces the amount of code on screen at once).

 

The following sections go into more detail on the above:

 

Busy coding or busy meeting ad.png