670

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?

Dynamic
  • 5,746
  • 9
  • 45
  • 73
fredley
  • 6,451
  • 3
  • 15
  • 17
  • 19
    http://stackoverflow.com/questions/578059/studies-on-optimal-code-width – Sotiris May 15 '12 at 10:45
  • 17
    Before anyone thinks of adding another answer to this question *please* read the accepted answer and [Mark Booth's answer](http://programmers.stackexchange.com/a/148729/47). These answer the question comprehensively. The punchcard came first. – ChrisF May 15 '12 at 20:54
  • 3
    Is it still the standard? Can't we get over it yet? I'd say 140 is more than acceptable with current displays (even smartphones). I chose 140 because it's the limit in Twitter, but 160 (doubling the previous) would fit as well... – Trylks Oct 13 '14 at 17:07
  • The standard is actually 79, if you're super-careful. Lines that are 80 characters long may cause wrapping when the file is dumped to an 80 column terminal unless the terminal is set to truncate long lines. In some terminals, under some configuration, when a character is printed in the 80th position, the cursor then advances to the start of the next line. When the carriage return/line-feed is issued, then a blank line results. I think most ANSI implementations do (are required?) to implement a shadow 81st column for this case, though, so the 80th char can be printed without this ill-effect. – Kaz Oct 19 '21 at 00:27
  • ... the "shadow 81st colum" meaning that when we print a character in the 80th column, the cursor goes to a 81st column. Then if another character is sent to the terminal at that position, the position will jump to the next line (scrolling if necessary), so the character appears there instead. That allows all 80 colums to be used by a text file, such that it can just be dumped to the terminal. – Kaz Oct 19 '21 at 00:29
  • Check also this question/answer: https://stackoverflow.com/questions/578059/studies-on-optimal-code-width/71182458#71182458 – DrBeco Feb 19 '22 at 05:42
  • also gopher standard is 67 chars long. – DrBeco Feb 19 '22 at 05:42
  • This question was featured in podcast "CoRecursive" in [episode 77](https://corecursive.com/why-80-columns/) (2022-06-01). – Peter Mortensen Jun 10 '22 at 10:23
  • Does the limit of 80 include the break line (character LF or characters CR+LF), or is it without? – Sandburg Aug 04 '23 at 07:19
  • How to manage the 80 limit with size-shifting encoding, like utf-8? – Sandburg Aug 04 '23 at 08:23
  • @Sandburg I think on modern computers, it's just about how much horizontal space it takes up, so the line break and encoding don't matter. – Solomon Ucko Aug 09 '23 at 03:54
  • @SolomonUcko I was really talking about encoding utf-8 with a hard limit of 80. So pure english manages to write 80 glyphs in 80, but literal chineese manages to write 20 glyphs in 80. What is the modern approach with dealing that? – Sandburg Aug 09 '23 at 06:37

9 Answers9

848

You can thank the IBM punch card for this limit - it had 80 columns:

IBM punch card

gnat
  • 21,442
  • 29
  • 112
  • 288
Oded
  • 53,326
  • 19
  • 166
  • 181
  • 72
    After that early teletypes, and later video terminals used 80 columns (and then 132 columns) as a standard width. – LapTop006 May 15 '12 at 11:43
  • 3
    @LapTop006 - Well, yes, but that's the historical start of the "standard"... – Oded May 15 '12 at 11:46
  • 3
    An old lecturer of mine gave me one of his old punch cards, I have no idea what the code represented on it does, but it makes a great bookmark and conversation piece. I was thinking of laminating it for posterity, but was afraid that it'd ruin it. – Jamie Taylor May 15 '12 at 12:37
  • 1
    @LapTop006 I am curious about the 132 standard now. Is that also a cary over from punch cards?s – Chad Harrison May 15 '12 at 14:01
  • 5
    @hydroparadise 132 columns is a carryover from line printer carriage widths. It was also standardized as an optional "extended" limit in one of the later Fortran versions, I believe. – Tim Lesher May 15 '12 at 14:19
  • 317
    Now the question is: Why did the IBM punch card have 80 columns? – Factor Mystic May 15 '12 at 14:23
  • 3
    Don't forget PC text mode. BIOS and DOS: 80 columns. – Kaz May 15 '12 at 16:38
  • 161
    @FactorMystic - the punch card size was based on the size of the currency back in the late 1880's's when Hollerith designed them to assist with [the 1890's census](http://columbia.edu/cu/computinghistory/census-tabulator.html). –  May 15 '12 at 14:51
  • 64
    The cards are that size because in 1890, CTR wanted to reuse currency carriers (the dollar was bigger back then) to carry the census data cards. – Al Biglan May 15 '12 at 17:30
  • 3
    80 columns does derive from punched cards (and that's why line numbers were used too because if you dropped a stack of punched cards you didn't need to sort them). 132 columns probably derived from the standard width of printer paper. – Cthutu May 15 '12 at 17:39
  • 9
    One reason for the card size has been given. How about a reason for the size and spacing of the holes required for the result to be 80? – hotpaw2 May 15 '12 at 20:15
  • 105
    @AlBiglan Why was currency that size? – fredley May 15 '12 at 23:13
  • 6
    Later 72 chars because of this: [3270 editor](http://www.canpub.com/teammpg/de/sim390/screens/editor.gif) – mplungjan May 16 '12 at 11:50
  • 3
    There were also a LOT of early dot matrix printers that had an 80 character width limit - ( and some/later wide ones with 132 characters) - so you had some 132 width stuff early on as well. – Mark Schultheiss May 16 '12 at 11:59
  • 3
    @hotpaw2 The spacing and size of the holes looks similar to those used by player pianos, I wouldn't be surprised to hear that they were reusing technology if not actual components. – Bill K May 16 '12 at 22:01
  • 40
    @fredley currency was that size so they could fit 80 characters of text on it ;-) – Jesse C. Slicer May 17 '12 at 18:38
  • 37
    The Pica typeface, which originated in the late 1700s and was used on typewriters, is typically 10 pitch. That puts 80 columns across a letter-sized page. I won't speculate about Why letter-sized pages are the size they are or what that has to do with railroad gauges or the ancient Romans. :-) – Blrfl May 18 '12 at 11:48
  • 5
    @Blrfl But that then begs the question why typewriters are typically 10 pitch. – dberm22 Sep 15 '15 at 16:49
  • 4
    There's a nice post on this: [The Tyranny of the Hollerith Punched Card](http://pub.gajendra.net/2012/09/hollerith_tyranny) – Maxime R. Jul 07 '16 at 08:27
  • 3
    @Blrfl [The precise origins of the dimensions of US letter-size paper are not known.](https://en.wikipedia.org/wiki/Letter_(paper_size)) – Jeyekomon Feb 08 '21 at 15:10
  • I understand all the points you make and recognize them. Now make a HTML file with proper intention and see how far you come with a 80 characters limit. It feels inconsistent with languages that simply frustrate one that tries to adapt those standards, but I guess this is just a luxury problem. – Martin Braun Jul 23 '21 at 22:56
300

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:

Cultural Impact

  • 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.

Now the question is, why did IBM chose 80 column cards in 1928, when Herman Hollerith had previously used 24 and 45 column cards?

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.

Mark Booth
  • 14,214
  • 3
  • 40
  • 79
  • 2
    Not to start another speculation-fest, but Hollerith's cards had circular holes, not the rectangles of the IBM 5081 _et al._ And IBM's later foray into cards, the System/3 format, had 96 circular holes in 3 horizontal bands of columns. – Ross Patterson May 15 '12 at 17:44
  • Wow, I get 230 characters across in my IDE ... – jcolebrand May 15 '12 at 17:50
  • what about Word wrap option? – abatishchev May 15 '12 at 18:28
  • 16
    A good reason to try to continue using 80 characters even on larger screens is that many programmers prefer to use smaller terminal (or even IDE) windows, rather than having to keep them full-screen at all times. – rkulla Jan 03 '13 at 17:34
  • 5
    @rkulla So for how many decades will should we continue to impose an 80 character limit? Sure for some languages like C with short identifiers it's fine but for others like C# with long identifiers, it can be a pain. Fortunately, we impose a 132 char limit where I am now but I used to get very annoyed with 80, especially in Python – Basic Apr 30 '13 at 15:21
  • 9
    @Basic there is an argument that if you can't work within an 80 character line limit then either your identifiers are *excessively* verbose or you are trying to do too much on one line. Most people are more comfortable with narrower columns of more lines than very long lines, since our eyes and brains have been trained for years through books, newspapers and column width constrained web pages (like this one) which mean that we find it hard to scan and comprehend *very* long lines. – Mark Booth Apr 30 '13 at 16:46
  • 5
    @MarkBooth I won't drag it out too much as it's a bit of a religious issue but one that gets flagged by PEP8 for being too long is ... ` (8 spaces) return HttpResponse(JsonLib().encode(Ret), content_type="application/json")` and yes it could be broken into multiple lines but it's scattered throughout various controllers and doesn't seem like it's worth splitting up except for meeting the 80-char "standard". – Basic Apr 30 '13 at 17:05
  • 132 Was also the the text width of a standard 80 column Dot matrix in compressed mode (circa early 1980's). I suggest its far more likely the Eclispe default configuration on 1920 wide screens is because 132 is so prevelent, 132 was obsolete before Eclipse was written... – mattnz Mar 31 '14 at 23:37
  • 1
    @mattnz I think that you have that the wrong way around. Dot matrix printers from the 1970's were almost certainly intended to duplicate line printers from the 1950's. 132 column compressed text was certainly intended to allow you to print out text meant for wide printers (11" at 12CPI) on narrow paper (8" at an eye watering 16.5CPI). – Mark Booth Apr 03 '14 at 11:13
  • @Mark Booth, drawing conclusions from line length to “your identifiers are too long, or you are trying to do too much in one line”, is just cobblers. – gnasher729 Oct 19 '21 at 22:03
  • 1
    Very good note about the three-way merge. Actually this is one of the major arguments next to code-reading speed/efficiency. I have worked on project with 90+ chars line length limit and merging was really bad (inefficient and error prone) especially in periods with high concurrent development activity. – sola Apr 28 '22 at 07:58
78

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.

sleske
  • 10,095
  • 3
  • 29
  • 44
  • 3
    I love this answer because it goes beyond specific technology and avoids the pursuit of the "true" original tech. – kakyo Jan 10 '19 at 15:33
  • 80 characters per line completely break reading ergonomics. You can see how Wikipedia is best-suited for reading and is particularly wider than other websites (including this one). A general rule is that whatever makes your code to need more scrolling to be read is a bad idea, because you lose context and you have to waste time scrolling in order to read something. I have plenty of code that proves this and I'm working on a formula which calculates a readability index and which proves you're wrong and that short lines are the worst. – Pablo Ariel Mar 30 '20 at 19:45
  • 1
    @PabloAriel: If you disagree with my answer, feel free to write your own. That's what this site is about. – sleske Mar 30 '20 at 20:38
  • Gopher text size is 67 width. – DrBeco Feb 19 '22 at 05:40
73

I'd say that's also because old terminals were (mostly) 80x24 characters in size: Back in the days of 80x24 terminals...

EDIT:

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.

Avio
  • 884
  • 5
  • 8
  • 8
    But old terminals were 80 characters wide because of http://programmers.stackexchange.com/a/148678/4767 – Oded May 15 '12 at 14:33
  • 10
    -1 for not reading prior answer and for useless link that says just _"Back in the days of 80x24 terminals, one of the original authors of a popular unix game was often complimented on how well his code was commented. He said that he had to do that because he always smoked pot when he coded and would lose his train of thought when the screen scrolled._" – gnat May 15 '12 at 14:40
  • 7
    Sorry for the welcome Avio, you just happened to jump in on a post that's got extremely popular! We do things a little differently from the rest of the internet around here. We hate duplication, amongst other things. Take a read of [the faq](http://programmers.stackexchange.com/faq) to get started, hope to see you again! – fredley May 15 '12 at 14:51
  • 6
    +1 to justify for downvote. Another +1 (if I could) because 80-character limit for code is **because of 80-column terminal** and that *in turn* may or may not be related to punchcards. – Sandman4 May 15 '12 at 15:00
  • 2
    @Oded can you _prove_ your point ? (Wikipedia is not a proof unless it have a source) – Sandman4 May 15 '12 at 15:12
  • 2
    @Oded How exactly punchcard`s 80x12=960bit=120bytes, related to 80 columns (7 or 8 bit) on a terminal ? Maybe 80x24=1920 is just the closest fit for 2kb of RAM that terminals had. – Sandman4 May 15 '12 at 15:18
  • 1
    @Sandman4 - You will notice that 80*24 fits _exactly_ two punch cards worth of data. – Oded May 15 '12 at 15:20
  • @Oded Hmmm... let me think... 80*24*7=13440 bit /80/12= _exactly_ 14 punchcards (sorry for being mean) – Sandman4 May 15 '12 at 15:24
  • 1 hole != 1 byte – Sandman4 May 15 '12 at 15:25
  • 1
    @Oded to be fair, _80*24=2x card_ bit of info is currently missing in your answer - leaving an impression that some dots are not quite connected – gnat May 15 '12 at 15:25
  • @Oded - besides, I presume people wasn't storing _screenshots_ :) on a punchcards - one _screen_ of code is not the same as 80x24 characters – Sandman4 May 15 '12 at 15:31
  • 1
    @Avio, maybe improve your post by adding a more appropriate link. – Sandman4 May 15 '12 at 15:36
  • 1
    @Avio: maybe you'll like this one: http://en.wikipedia.org/wiki/VT52 – Sandman4 May 15 '12 at 15:37
  • 1
    @Sandman4 - No, it isn't. But the fact that you have a multiple suggests that the original use of a terminal was to display the information from punch cards. – Oded May 15 '12 at 15:38
  • 1
    -1 for not knowing that 80-character VDTs owe their size to 80 columns punched cards. – Ross Patterson May 15 '12 at 17:29
  • 1
    @Sandman4 Wikipedia may not be a good reference, but it happens to be correct. We oldsters were writing code on IBM 029 keypunches onto IBM 5081-style cards long before the first commercial VDTs were available. – Ross Patterson May 15 '12 at 17:35
  • @Oded - "_You will notice that 80*24 fits exactly two punch cards worth of data_" is wrong. Each column holds a single character, encoded in "Hollerith code", requiring 1 or 2 punches in the same column. So 80*24 is really the same as 24 cards, sorry. – Ross Patterson May 15 '12 at 17:39
  • I think this is a relevant answer, because it addresses why 80 characters is still a standard limit. – Chance May 15 '12 at 19:27
  • 4
    +1 to counteract @RossPatterson's downvote. There are no citations on any wikipedia references to attribute the 80CPR to the punchcards; that may be completely coincidental, and a commonly accept "truth" that is not actually true. Show me an interview with one of the original engineers who specced the VT52 where he says they were following an IBM punchcard standard. – Jeremy Holovacs May 15 '12 at 20:07
  • 1
    What about overhead with line numbers, and other non-code bits in the termianl? I know the punchcard lacks these, but the terminal in a command-line IDE? – nanofarad May 15 '12 at 20:15
  • 3
    @RobertArkenin That's what we used columns 72-80 for - it was called the "sequence number" field. Anyone who ever dropped a deck of cards knew how to use sequence numbering to sort it back into order :-) – Ross Patterson May 15 '12 at 22:56
  • 1
    And here is the [editor that superseded the hole punch](http://www.canpub.com/teammpg/de/sim390/screens/editor.gif) – mplungjan May 16 '12 at 11:52
35

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.

Paul Marrington
  • 469
  • 3
  • 3
  • 5
    I've seen the 80-character (approximately) max width mentioned in typography discussions -- apparently it really does help readability, monospace or not. – nkorth Aug 13 '12 at 01:40
15

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.

Larry Tesler
  • 151
  • 2
7

I personally stick to "about column 80" for my end of line because further than that causes wrapping or lost code when you print it.

There's punch card legacy as well, but I don't think laser printers or 8.5x11 inch paper was set to conform to punch card limitations.

CMike
  • 103
  • 1
5

Scroll in printers papers were Letters size or 15" wide.

It were the 80 cps line printers for hardcopying of codes or reports, and later on Epson supports 132 cps condensed printing (escape code \015 for condensed print).

Rony
  • 207
  • 1
  • 1
  • Especially when it's written (several times!) on this page! – fredley May 15 '12 at 17:46
  • 12
    @Ross: you should not downvote anybody for not knowing something on **Q&A** site! – abatishchev May 15 '12 at 18:30
  • 6
    @abatishchev - but the answer being referred to is *on this page*. – ChrisF May 15 '12 at 20:35
  • 10
    @abatishchev Actually, that's exactly the idea of StackExchange sites. "Good" answers should be upvoted, and "bad" answers should be downvoted, to ensure that future readers who may not be able to judge for themselves can know the community's opinion of the answers. – Ross Patterson May 15 '12 at 22:54
  • @RossPatterson: I think that's sort of conservative and liberal points of view: should I downvote answers I don't like, or just leave them as is. If answer is not (totally) incorrect - I just leave them, that's just my personal attitude. – abatishchev May 16 '12 at 07:20
  • 2
    @abatishchev It isn't about voting down answers you don't like, it's about voting down answers which *aren't useful*. See the mouse-over text of the voting buttons. – Mark Booth Mar 31 '14 at 23:04
  • @RossPatterson The 'punch card' answers are probably less _useful_ than the answer that 'lots of media use line lengths between 60 and 100 characters'. – Jonathan Cast Nov 21 '17 at 20:14
2

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.

Ray Denton
  • 41
  • 2