2020-10-23 - limiting code line length

some time ago i came across an article / discussion if it is still reasonable to stick to 80 characters per line, when writing a source code. argument is fairly simple – 80c is a magic number, that happened to be a number of characters that one can fit on the text console in '80s and '90s, text-mode (so that you do not have to scroll). we now have 2020, full-HD or 4K wide screens. so why bother?

there is one more thing, though. when we read and need to skip to a new line, and the line is too long, we have trouble locating where the beginning of that new line is. this is no accident that newspapers are big, yet still feature multi-columns – it is just easier to read.

http://i.stack.imgur.com/kSlZe.png

this is also sth that trikes my nerve about dokuwiki i use here – lines can be just too long and annoying to read. i do plan to fix it – it's one of the “it will happen one day” projects.

so shall we back to 80c? i'd say no – 80c is arbitrary and fairly low, if you try to use descriptive names. also code is not a typical text. lines are not of an equal length. very often there are lines with just braces / parenthesis. this makes lines switching significantly simpler for human brain.

my personal rule of thumb is to try to keep it below 120c. on rare occasions i allow myself to reach up to 160c. otherwise i just break lines, introduce helper functions, etc.

in fact – this is how i typically work:

my workspace

i use dual screen setup: primary screen is horizontal while secondary i pivot to vertical. i edit code on secondary, so that i can benefit from seeing more context (more lines) at the expense of line lengths (which is still over 160c, thus more than enough for me). primary screen serves as a compilation output and/or documentation preview.

on top of this i use 20+ workspaces, to arrange my windows contextually. i3 tiling window manager of course, to minimize keyboard-mouse shifting.

over the years i found this setup to best suite my needs. YMMV, but please keep line lengths readable while not being 80c orthodox. there is a middle ground, that gets best out of both worlds.

blog/2020/10/23/2020-10-23_-_limiting_code_line_length.txt · Last modified: 2021/06/15 20:09 by 127.0.0.1
Back to top
Valid CSS Driven by DokuWiki Recent changes RSS feed Valid XHTML 1.0