Be Consistent in Line Lengths [DS24]

Be Consistent in Line Lengths [DS24]

Tip DS24

While absolutely consistency in line lengths isn’t typically achievable, highly inconsistent line lengths when reading/working on some particular piece of code can be incredibly distracting and impose an unnecessary cognitive load on readers. Consistency helps readability.

While code syntax itself will dictate the length of some lines, generally have more flexibility. When laying out comments in relation to code, consider making comments about as long as the longest/average line of code visible on screen at once. Such consistency within a reader’s “field-of-view” is often helpful and prevents jarring shifts.

Below's an example of some highly distracting variations in comment length:

Code in the zone ad.png