Why is 80 characters the "standard" limit for code width? Why 80 and not 79, 81 or 100? What is the origin of this particular value?
You can thank the IBM punch card for this limit - it had 80 columns:
As oded mentioned, this common coding standard is a result of the IBM's 1928 80 column punched card format, since many coding standards date back to a time when programs were written on punch cards, one card/line at a time, and even the transition to wider screens didn't alter the fact that code gets harder to read the wider it becomes.
From the wikipedia page on punched cards:
- A legacy of the 80 column punched card format is that a display of 80 characters per row was a common choice in the design of character-based terminals. As of November 2011 some character interface defaults, such as the command prompt window's width in Microsoft Windows, remain set at 80 columns and some file formats, such as FITS, still use 80-character card images.
Although I can't find a definitive answer, I suspect that the choice was based on the typical number of characters per line of typewriters of the time.
Most of the historical typewriters I've seen had a platen width of around 9 inches, which corresponds with the standardisation of paper sizes to around 8"-8.5" wide (see Why is the standard paper size in the U.S. 8 ½" x 11"? and the History of ISO216 A series paper standard).
Add a typical typewriter pitch of 10-12 characters per inch and that would lead to documents with widths of between 72 and 90 characters, depending on the size of the margins.
As such, 80 characters per line would have represented a good compromise between hole pitch (small rectangular vs. larger round holes) and line length, while maintaining the same card size.
Incidentally, not everywhere specifies an 80 character line width in their coding standards. Where I work has a 132 character limit, which corresponds to the width of typical wide line printers of yore, a 12pt landscape A4 printout and the typical line width remaining in an editor window of Eclipse (maximised on a 1920x1200 screen) after Package Explorer and Outline views are taken into account.
Even so, I still prefer 80 character wide code as it it makes it easier to compare three revisions of a file side-by-side without either scrolling sideways (always bad) or wrapping lines (which destroys code formatting). With 80 character wide code, you only need a 240 character wide screen (1920 pixels at 8 pixels per character) to see a full three-way-merge (common ancestor, local branch and remote branch) comfortably on one screen.
I'd say that's also because old terminals were (mostly) 80x24 characters in size: Back in the days of 80x24 terminals...
To answer more precisely and more thoroughly to the question, 80 characters is the current "universally accepted" limit to code width inside editors because 80x24 and 80x25 formats were the most common screen modes in early I/O terminals and personal computers (VT52 - thanks to Sandman4).
This limit is still valid and somehow important IMHO for two main reasons: the default geometry that many Linux distros assign to newly spawned terminal windows is still 80x24 and many people use them as-is, without resizing. Moreover, kernel, real-time and embedded programmers often work in a "headless" environment without any window manager. Again, the default screen resolution is often 80x24 (or 80x25), and, in these situations, it may even be difficult to change this default setting.
So if you are a kernel, real-time or embedded programmer you should force yourself to respect this limit, just to be a little more "friendly" towards any programmer that should read your code.
While probably not the original reason for the 80 character limit, a reason that it was accepted widely is simply reading ergonomics:
- If lines are too short, text becomes hard to read because you must constantly jump from one line to the next while reading.
- If lines are too long, the line jumping becomes too hard because you "lose the line" while going back to the start of the next line (this can be mitigated by having a bigger inter-line spacing, but this also wastes space).
This is widely known and accepted in typography. The standard recommendation (for text in books etc.) is to use something in the region of 40-90 characters per line, and ideally about 60 (see e.g. Wikipedia, Markus Itkonen: Typography and readability.
If you aim for 60 characters per line, your upper limit must obviously be a bit higher to accommodate the occasional long expression (and things like margins markers and line numbers), so having an upper limit of 70-80 makes sense.
This probably explains why the 80 character limit was taken over by many other systems.
A related question is "why has 80 column persisted". Even the responses on this page are approximately that width. I agree with the historical reasons for 80 columns, but the question is why the standard has persisted. I would claim readability - for prose and code. Our minds can only absorb so much information in one piece. I still use the 80 column marker in my code editor to remind me when a statement is getting too long and obscure. It also leaves me plenty of screen real-estate for the browser, and the supporting IDE windows. Long live 80 column - as a guide not a rule.
Another common line length limit in the days of fixed pitch fonts was 72 characters. Examples: Fortran code, mail, news.
One reason was that columns 73-80 of a punch card were often reserved for a serial number. Why a serial number? If you dropped a card deck, you could pick the cards up in any order, line up the upper left corners (which always had a diagonal cut) and use a card sorting machine to get them back in order.
Another reason for the 72-character limit was that common fonts were 10 points high and 6 points (1/12") wide. An A4 or 8.5" wide page could hold 72 characters in a 6" wide column and still have room for margins of over an inch.
One of the reasons for the 80 column cards may be associated with the 'hand punch' which was probably in use before the electronic card punch machines. It is one which I used in the early 70s on an ICL System 4-50 main frame computer site. One had to punch a section of three? punch knives in the carriage at the same time.