182

Seriously. On a 22" monitor, it only covers maybe a quarter of the screen. I need some ammo to axe down this rule.


I'm not saying that there shouldn't be a limit; I'm just saying, 80 characters is very small.

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
TraumaPony
  • 10,742
  • 12
  • 54
  • 74
  • All answers pretty much state what I wanted to add. To give you a real life example - I have a x61s, the resolution is 1024x768. When I am on the road, I don't have my fancy monitor. Opening code in my IDE is a pain when it exceeds this rule. – Till Sep 21 '08 at 13:10
  • possible duplicate of http://stackoverflow.com/questions/95575/while-coding-how-many-columns-do-you-format-for –  Apr 10 '10 at 21:27
  • Even if you have a set of 3 monitors. This is not a reason to shaking head right to left and back. Forever. Ah-ha-ha. Actually the eye moves faster than head. Do you know about columns into newspapers? The reason of the width is the eye/head/man convenience. – Ivan Black May 20 '16 at 20:22
  • Related post - [Why is 80 characters the 'standard' limit for code width?](https://softwareengineering.stackexchange.com/q/148677/236257) & [Studies on optimal code width?](https://stackoverflow.com/q/578059/465053) – RBT Jun 18 '19 at 08:16
  • 4
    Update 12/13/2021: Merged : The Linux kernel has officially deprecated its coding style that the length of lines of code comply with 80 columns as the "strong preferred limit".31-May-2020 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bdc48fa11e46f867ea4d75fa59ee87a7f48be144 – Israr Dec 13 '21 at 18:10

32 Answers32

289

I think the practice of keeping code to 80 (or 79) columns was originally created to support people editing code on 80-column dumb terminals or on 80-column printouts. Those requirement have mostly gone away now, but there are still valid reasons to keep the 80 column rule:

  • To avoid wrapping when copying code into email, web pages, and books.
  • To view multiple source windows side-by-side or using a side-by-side diff viewer.
  • To improve readability. Narrow code can be read quickly without having to scan your eyes from side to side.

I think the last point is the most important. Though displays have grown in size and resolution in the last few years, eyes haven't.

micrub
  • 740
  • 8
  • 17
Will Harris
  • 21,597
  • 12
  • 64
  • 64
  • 2
    You don't need eyes with higher resolution, or simply "bigger eyes", to read long lines. ;) I doubt long lines even make code harder to scan, unless each line is significantly long (100+ chars). – steffenj Oct 23 '08 at 16:05
  • 7
    They may have "largely gone away", but not entirely. I tend to work with two different setups: 1) in an ssh window connected to a remote machine. which is 80 characters wide by default. and 2) In Visual Studio, with two panels side-by-side so I can see header and cpp file at the same time. – Enno Nov 13 '08 at 21:27
  • 13
    @steffenj: Actually, books tend to shoot for about 66 characters per line (although this varies somewhat depending on other parameters) because longer lines *do* make reading more difficult. Maximum _code_ line length could be argued, but 80 is convenient for historical and practical reasons. – Steve S Jan 26 '09 at 16:53
  • 86
    The problem is by forcing people to keep line lengths short they tend to use less meaningfull names.. – Ian Ringrose Jan 21 '10 at 07:46
  • 9
    I find the remarks about readability quite interesting, because the thing I really hate about printed programming articles/books/... is, that the short lines which are used for the code examples are so extremely hard to read. It can make a lot of sense to move something to a new line, but the grouping should occur logically, dissecting the expression recursively, not because the output device accidentally reached its limitation. IOW, I find that devices which impose such narrow restrictions are not well suited to display code. – Chris Lercher Mar 30 '10 at 13:51
  • 3
    I'm with @Enno, a wider screen means room for two 80-column files, not one mostly-80-column-with-a-few-honkin-long-lines and an editor full of unused space :) It's also important that current editors *do* have the ability to scroll horizontally so if a line *should* be more than 80 characters long, it's perfectly safe to leave it so. – Cheezmeister Feb 22 '11 at 18:04
  • Quibble re *Narrow code can be read quickly* ... sometimes however I like to trade a bit of tennis viewing neck for less scroll wheel finger strain if I can make a significant line count reduction by using some of the vast darkness to the right. Long and narrow isnt *always* better than shorter and a little wider. (Yes fnarr fnarr but how would you say it) – Ruben Bartelink Sep 03 '14 at 12:34
  • 11
    I think the problem with 80-column enforcers is that they forget that the code instead grows in the vertical direction. You get the same problem, but in the vertical direction AND of top of this modern code looks awful when you have to break single statements over two or sometimes up to four or five lines. It is NOT more readable. With modern code I mean descriptive variable names and qualifying inheritance, namespaces, classes etc. Please stop the 80 column nonsese, use common sense instead. 120 is better, but should not be a rule either. – Larswad Feb 02 '15 at 17:24
  • Rust selected 99 as a sensible standard: https://aturon.github.io/style/whitespace.html – phoenix Jan 05 '16 at 00:46
  • According to [PSR-2](http://www.php-fig.org/psr/psr-2/): `There MUST NOT be a hard limit on line length; the soft limit MUST be 120 characters; lines SHOULD be 80 characters or less.` – aesede Apr 08 '16 at 11:15
  • 1
    (As of 2020) Also, what if you have to read your code on a smartphone? – The_Sympathizer Jul 23 '20 at 05:33
  • I'd also add that if one is going to go wider with wanting to take advantage of a wide monitor, a good rule of thumb would be _right hand scrolling is evil._ Don't have to scroll right to follow a line of code. – The_Sympathizer Jul 23 '20 at 05:34
  • 1
    Personally I think 80 encouraged... 80 - 85 is neglect-able. 90 - 100 is an absolute max. up to 120 is exceptional. Stick to 120+ you'll probably be in need of anger management therapie at some point. There is an Enter key on your keyboard you know – Khalil Gharbaoui Nov 24 '20 at 22:19
87

The origin of 80-column text formatting is earlier than 80-column terminals -- the IBM punch card dates back to 1928, and its legacy to paper tapes in 1725! This is reminiscent of the (apocryphal) story that the US railway gauge was determined by the width of chariot wheels in Roman Britain.

I sometimes find it a bit constricting, but it makes sense to have some standard limit, so 80 columns it is.

Here's the same topic covered by Slashdot.

And here's an old-school Fortran Statement:

FORTRAN punch card

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
John Carter
  • 53,924
  • 26
  • 111
  • 144
63

80 characters is a ridiculous limit these days. Split your code lines where it makes sense, not according to any arbitrary character limit.

Craig Day
  • 2,525
  • 1
  • 24
  • 26
  • 2
    The character limit does not tell you WHERE you have to split a line of code, but WHEN – gztomas Aug 25 '15 at 16:30
  • 2
    No it is not. If you write a longer than 80 chars line, you probably already have a problem in expression complexity or naming strategy. As others have mentioned, readability is a top concern and reading speed starts dropping above 60-66 chars (typography, based on human physiology). – sola Apr 17 '18 at 08:55
  • 1
    @sola Your comment appears here with 98 chars, and it is a dense natural non-native language (to me) to understand. Completely legible. A code with until 3-4 indents, syntax markers etc. is even easier. – dawid Jun 03 '20 at 23:38
  • I accidentally downvoted this answer and can no longer upvote it. :( – Andy Jun 25 '20 at 10:30
  • @vlyps It may feel completely legible but that doesn't mean that you couldn't read it much faster if it was shorter. Indents do help in general but not much when you are at 100+ chars per line. – sola Aug 05 '20 at 20:06
  • @sola Nonsense! You are assuming there is no such thing as vertical noise. All that shorter sentences mean is that you have more bleed into the vertical which is just as legibly problematic. Often worse. There are better ways to structure code and any other language than an adherence to arbitrary character limits. – SacredGeometry Feb 22 '22 at 14:05
  • @SacredGeometry: The horizontal limit is not arbitrary. Human reading speed starts dropping above 60-66 chars width. This has been established by research ages ago and is the basis of typography and website design as well. Obviously, the code will be longer vertically but you will read through it much quicker, especially if correct indentation rules are observed. – sola Feb 23 '22 at 10:45
  • @sola Those studies had literally nothing to do with programming they where to do with normal text (mostly) in the english language. They are pretty dubious not to mention especially when you consider that they contradict how many languages fundamentally work. Not to mention were part of the vast replication crisis in psych. – SacredGeometry Feb 23 '22 at 10:53
  • @sola This fashion of blindly espousing bad science as if were fact because someone has written a paper about it, rather than treating it as what it is i.e. merely popularised conjecture is pretty endemic. – SacredGeometry Feb 23 '22 at 10:55
36

You should just do it for the sake of everyone who doesn't have a 22 inch widescreen monitor. Personally, I work on a 17 inch 4:3 monitor, and I find that more than sufficiently wide. However, I also have 3 of those monitors, so I still have lots of usable screen space.

Not only that, but the human eye actually has problems reading text if the lines are too long. It's too easy to get lost in which line you are on. Newspapers are 17 inches across (or somethign like that), but you don't see them writing all the way across the page, same goes for magazines and other printed items. It's actually easier to read if you keep the columns narrow.

Kibbee
  • 65,369
  • 27
  • 142
  • 182
  • 17
    Not when you add indenting into the mix. If you use 4 spaces per indent, and you're in something like, namespace->class->method->if->for, that's 1/5th of your space blown. – TraumaPony Sep 21 '08 at 12:50
  • You could always set the rule at 80 chars from the indent. That way the eye can easily follow it. – Vincent McNabb Sep 21 '08 at 13:09
  • Sometimes, (but not always) I wish .Net had automatic namespacing so that your didn't have to define the namespace in the file. That seriously messes with the alignment of your code. if you want nested namespaces, you have really big problems. – Kibbee Sep 21 '08 at 14:48
  • 15
    However, reading prose is not the same as reading code. – Atario Nov 17 '08 at 20:27
  • 3
    +1 for newspapers, great example. @Atario, reading GOOD code is very much like reading prose. – Todd Chaffee May 18 '12 at 18:37
  • @ToddChaffee I like plot twists in prose; not so much in code :) – Ben Sep 22 '16 at 17:39
  • @ben so everything all on one line, right? ;-) – Todd Chaffee Sep 23 '16 at 18:39
  • @ToddChaffee No, more the feeling that in some code variables change behavior in surprising, confusing, and sometimes devastating ways :) j – Ben Sep 23 '16 at 18:58
  • @ben we aren't talking about line length anymore, are we? – Todd Chaffee Sep 25 '16 at 12:08
  • @ToddChaffee I just thought too deeply about your simile haha. Those global variables in some code I inherit are used for too many things and it can take a lot of time to figure out where they're from, or what they're doing, or what they'll do to other variables. Stuff I would enjoy if they were characters in a novel. – Ben Sep 25 '16 at 19:31
27

When you have a sequence of statements that repeat with minor variations it can be easier to see the similarities and differences if the they are grouped into lines so that the differences align vertically.

I'd argue that the following is much more readable than it would have been if I'd split it over multiple lines:

switch(Type) {
case External_BL:   mpstrd["X"] = ptDig1.x - RadialClrX;    mpstrd["Y"] = ptDig1.y - RadialClrY;    break;
case External_BR:   mpstrd["X"] = ptDig1.x + RadialClrX;    mpstrd["Y"] = ptDig1.y - RadialClrY;    break;
case External_TR:   mpstrd["X"] = ptDig1.x + RadialClrX;    mpstrd["Y"] = ptDig1.y + RadialClrY;    break;
case External_TL:   mpstrd["X"] = ptDig1.x - RadialClrX;    mpstrd["Y"] = ptDig1.y + RadialClrY;    break;
case Internal_BL:   mpstrd["X"] = ptDig1.x + RadialClrX;    mpstrd["Y"] = ptDig1.y + RadialClrY;    break;
case Internal_BR:   mpstrd["X"] = ptDig1.x - RadialClrX;    mpstrd["Y"] = ptDig1.y + RadialClrY;    break;
case Internal_TR:   mpstrd["X"] = ptDig1.x - RadialClrX;    mpstrd["Y"] = ptDig1.y - RadialClrY;    break;
case Internal_TL:   mpstrd["X"] = ptDig1.x + RadialClrX;    mpstrd["Y"] = ptDig1.y - RadialClrY;    break;
}

Update: In the comment's it's been suggested that this would be a more succinct way of doing the above:

switch(Type) {
  case External_BL: dxDir = - 1; dyDir = - 1; break;
  case External_BR: dxDir = + 1; dyDir = - 1; break;
  case External_TR: dxDir = + 1; dyDir = + 1; break;
  case External_TL: dxDir = - 1; dyDir = + 1; break;
  case Internal_BL: dxDir = + 1; dyDir = + 1; break;
  case Internal_BR: dxDir = - 1; dyDir = + 1; break;
  case Internal_TR: dxDir = - 1; dyDir = - 1; break;
  case Internal_TL: dxDir = + 1; dyDir = - 1; break;
}
mpstrd["X"] = pt1.x + dxDir * RadialClrX;
mpstrd["Y"] = pt1.y + dyDir * RadialClrY; 

although it now fits in 80 columns I think my point still stands and I just picked a bad example. It does still demonstrate that placing multiple statements on a line can improve readability.

Sam Hasler
  • 12,344
  • 10
  • 72
  • 106
  • 11
    By saying that there are only small differences from line to line, you also say, that there is a lot of redundant code. Removing some of that could significantly decrease the number of columns and still be vertically aligned. – foraidt Oct 23 '08 at 16:29
  • @mxp: agreed. If there's a more concise way of writing the above I'd be interested to see it. – Sam Hasler Oct 24 '08 at 13:01
  • 1
    I agree with the general idea, but the example... What about this: switch(...) { case ...BL: dxDir = - 1; dyDir = - 1; break; case ...BR: dxDir = + 1; dyDir = - 1; break; ... } ...["X"] = pt1.x + dxDir * Rad...X; ...["Y"] = pt1.y + dyDir * Rad...Y; – Yarik Oct 27 '08 at 08:29
  • Oops... Code sample in comments looks ugly. But I hope you got the idea. :-) – Yarik Oct 27 '08 at 08:30
  • @sam: The idea is that if you seen such long lines as in your original example it's probably should be re-factored to make a code more efficient. Long lines usually mean bad code (not always just usually) – Ilya Nov 10 '08 at 07:33
  • 51
    The fact that I need to scroll the first of the two examples horizontally kind of proves the pint about shorter lines being better :-) – Enno Nov 13 '08 at 21:30
  • 1
    I don't understand the hate for scrolling? It's a common opinion, and I'm not saying it's wrong, I just don't understand it. Especially if you're in a code editor, you don't even need to move your hands off the keyboard to get to the mouse -- just `(ctrl+)arrow` over or hit `end` – KOGI Jul 13 '13 at 00:10
  • [Visual field limits](https://en.wikipedia.org/wiki/Visual_field#Normal_limits) – micrub Aug 09 '16 at 19:17
  • In my experience, such vertical alignment of statement groups usually comes in places of table-like code. My argument to it is maybe, if code wants to be table-like, make it a table explicitly. For this example, in e.g. C++, it's a container `directions` of dx-dy pairs, perhaps in a struct `Dir` (container being `vector` if `Type`s are consecutive, or `map` if not). Then this sample becomes `auto dir = directions[Type]; mpstrd["X"] = pt1.x + dir.dx * RadialClrX; mpstrd["Y"] = pt1.y + dir.dy * RadialClrY;` – S. Kalabukha Jun 16 '22 at 08:26
  • @S.Kalabukha That's a very good sugestion worthy of its own answer – Sam Hasler Aug 01 '22 at 15:18
  • @enno No it doesn't; it proves that SO doesn't adapt to the size of the window. – Jim Balter Sep 02 '23 at 02:27
23

Printing a monospaced font at default sizes is (on A4 paper) 80 columns by 66 lines.

Josh
  • 61
  • 1
  • 4
17

I use the the advantage of bigger screens to have multiple pieces of code next to eachother.

You won't get any ammo from me. In fact, I'd hate to see it changed since in emergencies I still see rare cases where I need to change code from a text-console.

Twan
  • 438
  • 3
  • 8
14

Super-long lines are harder to read. Just because you can get 300 characters across on your monitor doesn't mean you should make the lines that long. 300 characters is also way too complex for a statement unless you have no choice (a call that needs a whole bunch of parameters.)

I use 80 characters as a general rule but I'll go beyond that if enforcing it would mean putting a line break in an undesirable location.

Loren Pechtel
  • 8,945
  • 3
  • 33
  • 45
  • There are studies that show that people can read and follow x amount of characters/words, before they loose track. I am thinking 80 is in there somewhere. I don't have any sources to back that up though. – Till Sep 21 '08 at 13:19
  • Yeah, I think really, it's not about keeping the lines short so much as about keeping the lines clean/concise/readable/understandable. – KOGI Jul 13 '13 at 00:12
  • If you have a (a call that needs a whole bunch of parameters.) you need to do some refactoring anyway. – Zarremgregarrok Oct 06 '14 at 13:33
  • @Zarremgregarrok I've seen some very long parameter lists in Microsoft APIs. – Loren Pechtel Oct 06 '14 at 17:29
  • @LorenPechtel Does that make it well written? – Zarremgregarrok Oct 21 '14 at 10:00
9

The only thing I enforce to stay within 80 chars is my commenting.

Personally...I'm devoting all my brain power (what little there is) to coding right, it's a pain to have to go back and break everything up at the 80 char limit when I could be spending my time on the next function. Yes, Resharper could do it for me I suppose but then it freaks me out a little that a 3rd party product is making decisions on my code layout and changes it ("Please don't break my code into two lines HAL. HAL?").

That said, I do work on a fairly small team and all of our monitors are fairly large so worrying about what bothers my fellow programmers isn't a huge concern as far as that goes.

Seems though some languages encourage longer lines of code for the sake of more bang for the buck (short hand if then statements).

domusvita
  • 818
  • 7
  • 7
8

In the Linux coding standard, not only do they keep the 80 character limit, but they also use 8 space indentation.

Part of the reasoning is that if you ever reach the right margin, you should consider moving an indentation level into a separate function.

This will make clearer code because regardless of indentation lengths, it is harder to read code with many nested control structures.

Ali
  • 1,014
  • 2
  • 12
  • 17
7

The other answers already summed things up nicely, but it is also worth considering when you might want to copy & paste some code into an email, or if not code then a diff.

That's a time when having a "max width" is useful.

7

I have two 20" 1600x1200 monitors and I stick to 80 columns because it lets me display multiple text editor windows side-by-side. Using the '6x13' font (the trad. xterm font) 80 columns take up 480 pixels plus the scrollbar and window borders. This allows one to have three windows of this type on a 1600x1200 monitor. On windows the Lucida Console font won't quite do this (the minimun usable size is 7 pixels wide) but a 1280x1024 monitor will display two columns and a 1920x1200 monitor such as an HP LP2465 will display 3. It will also leave a bit of room at the side for the various explorer, properties and other windows from Visual Studio.

Additionally very long lines of text are hard to read. For text the optimum is 66 characters. There is a point where excessively long identifiers start to be counterproductive because they make it hard to lay out code coherently. Good layout and indentation provides visual cues as to the code structure and some languages (Python comes to mind) use indentation explicitly for this.

However, The standard class libraries for Java and .Net tend to have a preponderance of very long identifiers so one cannot necessarily guarantee to be able to do this. In this case, laying out code with line-breaks still helps to make the structure explicit.

Note that you can get windows versions of '6x13' fonts Here.

ConcernedOfTunbridgeWells
  • 64,444
  • 15
  • 143
  • 197
  • Thank you for saying this! Big monitors are all the *more* reason for the 80 line limit, so you can fit more windows side-by-side. Not to mention that it's nice to be able to print source code (on paper) sometimes. Or paste snippets into other documents. – dreeves Jan 02 '09 at 09:50
6

People say long lines of code tend to be complex. Consider a simple Java class:

public class PlaintiffServiceImpl extends RemoteServiceServlet implements PlaintiffService {

This is 94 characters long and the class name is quite short (by GWT standards). It would be difficult to read on 2 lines and it is very readable on one line. Being pragmatic about it and thus allowing "backwards compatibility", I'd say 100 characters is the right width.

Matyas
  • 311
  • 1
  • 4
  • 14
  • 13
    I'm not a fan of horizontal scrollbars – bryc Feb 28 '15 at 09:34
  • 17
    I'm surprised no one has said this, given that I'm several years late to this discussion, but I think newlines (maybe with an indent for clarity) right before "extends" and/or "implements" keywords would still produce very readable code. – mtraceur Nov 13 '15 at 19:21
  • 11
    I love the fact that it says "it is very readable on one line" while at the same time I can't read the entire code snippet since it overflows the horizontal space in the browser. Point disproven. – oligofren Oct 04 '18 at 11:17
  • @oligofren It doesn't overflow the horizontal space in the browser, it overflows the narrow widths that SO uses. The point proven here is that there are a lot of crappy tools that don't adapt correctly for window size, etc. People talk about lines getting truncated in their IDEs because their IDEs are too dumb wrap lines or because they haven't turned on that option. – Jim Balter Sep 02 '23 at 02:24
5

You are not the only person who is going to maintain your code.

The next person who does might have a 17" screen or might need large fonts to read the text. The limit has to be somewhere and 80 chars is the convention due to previous screen limitations. Can you think of any new standard (120) and why it is a good idea to use that other then "that's what fits on my monitor at Xpt font?"

Remember, there are always exceptions to every rule so it you have a particular line or block of code that makes sense to be more than 80 chars then be a rebel.

But take the time first to think "is this code really that bad that it can not live within 80 chars?"

pappes
  • 433
  • 1
  • 3
  • 6
  • 1
    I will live with 80 chars when I can have 2spc tabstops. Better yet, actually use tabs for indentation, the requirement is when tabsize = 2, fits in 80 columns, use 4 most of the time for better readability. That way when you really have to choke down to 80 columns you can, but at a price. – Joshua Jan 26 '09 at 16:52
  • If you are working professionally on a 17" screen with a resolution of 1024x768 in 2022 then sorry you are not someone we should be caring about catering for. If your tooling is forcing that limit on you then you are using out of date tools. It's a very tenuously disguised mandate by bad programmers to try to force even worse programmers to write "better" code all it actually does, however is make everyone write badly formatted code. – SacredGeometry Feb 22 '22 at 14:07
5

I've widened my code out to 100 characters which fits comfortably in less than half my screen on my Macbook. 120 characters is probably the limit before lines start to get too long and complex. You don't want to get too wide else you encourage compound statements and deeply nested control structures.

The right margin is nature's way of telling you to perform an extra method refactoring.

Schwern
  • 153,029
  • 25
  • 195
  • 336
5

I wonder if this might cause more problems in this day and age. Remember that in C (and possibly other languages) there are rules for how long a function name can be. Therefore, you often see very hard-to-understand names in C code. The good thing is that they don't use a lot of space. But every time I look at code in some language like C# or Java the method names are often very long, which makes it close to impossible to keep your code at a 80 characters length. I don't think 80 characters are valid today, unless you need to be able to print the code, etc.

Jonas
  • 4,107
  • 3
  • 21
  • 25
5

As the author of coding guidelines for my employer I have upped the line length from 80 to 132. Why this value? Well, like others pointed out, 80 is the length of many old hardware terminals. And 132 is as well! It's the line width when terminals are in wide mode. Any printer could also make hardcopies in wide mode with a condensed font.

The reason for not staying at 80 is that I rather

  • prefer longer names with a meaning for identifiers
  • not bother with typedefs for structs and enums in C (they are BAD, they HIDE useful information! Ask Peter van der Linden in "Deep C Secrets" if you don't believe it), so the code has more struct FOO func(struct BAR *aWhatever, ...) than code of typedef fanatics.

and under these rules just 80 chars/line cause ugly line wraps more often than my eyes deem acceptable (mostly in prototypes and function definitions).

Jens
  • 69,818
  • 15
  • 125
  • 179
4

As others have said, I think it's best for (1) printing and (2) displaying multiple files side by side vertically.

Thomas Owens
  • 114,398
  • 98
  • 311
  • 431
4

I like to limit my width to 100 chars or so to allow two SxS editors on a widescreen monitor. I don't think that there is any good reason for a limit of exactly 80 chars anymore.

Jamie Eisenhart
  • 180
  • 1
  • 5
4

Use proportional fonts.

I'm serious. I can usually get the equivalence of 100-120 characters in a line without sacrificing readability or printability. In fact it's even easier to read with a good font (e.g., Verdana) and syntax coloring. It looks a little strange for a few days, but you quickly get used to it.

bgiles
  • 1,200
  • 11
  • 12
  • Really bad idea when you want to use 'indents' and a monospaced fonts. – Bersaelor Jul 31 '15 at 10:32
  • 3
    @Bersaelor No, it works fine when you always indent using tabs only and set the tab width properly (width 4 monospaced are like maybe 7 proportional). Indentation works, you just can't do ASCII art, but I don't think ASCII art belongs in code. – maaartinus Jan 08 '17 at 02:17
  • Personally, I am quite on the opposite side when programming. I find proportional code really hard to read. Sometimes, I even configure the IDE to use monospace fonts (yes, including menus). – Sebastian Mach Oct 18 '18 at 12:10
3

There's already a lot of good answers to this, but it's worth mentioning that in your IDE you might have a list of files on the left, and a list of functions on the right (or any other configuration).

You're code is just one part of the environment.

Dean Rather
  • 31,756
  • 15
  • 66
  • 72
2

I try to keep things down near 80 characters for a simple reason: too much more than that means my code is becoming too complicated. Overly verbose property/method names, class names, etc. cause as much harm as terse ones.

I'm primarily a Python coder, so this produces two sets of limitations:

  1. Don't write long lines of code
  2. Don't indent too much

When you start to reach two or three levels of indentation, your logic gets confusing. If you can't keep a single block on the same page, your code is getting too complicated and tricky to remember. If you can't keep a single line within 80 characters, your line is getting overly complicated.

It's easy in Python to write relatively concise code (see codegolf) at the expense of readability, but it's even easier to write verbose code at the expense of readability. Helper methods are not a bad thing, nor are helper classes. Excessive abstraction can be a problem, but that's another challenge of programming.

When in doubt in a language like C write helper functions and inline them if you don't want the overhead of calling out to another function and jumping back. In most cases, the compiler will handle things intelligently for you.

Dan Udey
  • 2,967
  • 2
  • 21
  • 18
2

I'm diffing side-by-side all day long and I don't have a freakin' 22 inch monitor. I don't know if I ever will. This, of course, is of little interest to write-only programmers enjoying arrow-coding and 300-char lines.

Constantin
  • 27,478
  • 10
  • 60
  • 79
1

I actually follow a similar rule for my own code but only because of printing code to an A4 page - 80 columns is about the right width for my desired font size.

But that's personal preference and probably not what you were after (since you want ammo to go the other way).

What don't you question the reasoning behind the limit - seriously, if no-one can come up with a good reason why it's so, you have a good case for having it removed from your coding standards.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
1

I thing not enforcing 80 characters means eventually word wrapping.
IMO, any length chosen for a max-width line is not always appropriate and word wrapping should be a possible answer.
And that is not as easy as it sound.

It is implemented in jeditalt text
(source: jedit.org) which offers word wrap

But it is bitterly missed in eclipse from a looong time ! (since 2003 in fact), mainly because a word wrap for text editor involves:

  • Wrapped line information is for the text viewer, code navigation, vertical rulers.
  • Unwrapped line information is required for functionalities like goto line, line numbering ruler column, current line highlight, saving file.
Glorfindel
  • 21,988
  • 13
  • 81
  • 109
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Yes, because even in this day and age, some of us are coding on terminals (ok, mostly terminal emulators), where the display can only display 80 chars. So, at least for the coding I do, I really appreciate the 80 char rule.

CobolGuy
  • 319
  • 1
  • 3
  • 8
1

I force my students to squeeze into 80 columns so I can print out their code and mark it up.

And about 17 years ago I let my own code expand to 88 columns, because I started doing everything using Noweb and 88 columns is what fits in a nicely printed document using TeX.

I indent by only two spaces, but the extra room is wonderful.

Norman Ramsey
  • 198,648
  • 61
  • 360
  • 533
0

I still think that the limit isn't limited on the visual part. Sure, the monitors and resolutions are big enough to show even more characters in one line nowadays, but does it increase the readability?

If the limit is really enforced it's also a good reason to re-think the code and not to put everything into one line. It's the same with indentation - if you need to much levels your code needs to be re-thought.

unexist
  • 2,518
  • 23
  • 27
0

Breaking at 80 characters is something you do while coding, not afterwards. Same with comments, of course. Most editors can assist you in seeing where the 80-characters limit is.

(This may be a little OT, but in Eclipse there is an option which formats the code when you save it (according to whatever rules you want). This is a little freaky at first, but after a while you start to accept that the formatting is no more in your hands than the generated code is.)

JesperE
  • 63,317
  • 21
  • 138
  • 197
0

If we had one of these, we wouldn't be having this discussion! ;-)

But seriously the issues that people have raised in their answers are quite legitimate. However the original poster was not arguing against a limit, merely that 80 columns is too few.

The issue of emailing code snippets has some merit. But considering the evil things that most email clients do to pre-formatted text I think that line wrapping is only one of your problems.

As for printing I usually find that 100 character lines will very comfortably fit onto a printed page.

Community
  • 1
  • 1
Andrew Edgecombe
  • 39,594
  • 3
  • 35
  • 61
0

I try and keep my lines below 80 columns. The strongest reason is that i often find myself using grep and less to browse my code when working at the command-line. I really don't like how terminals are breaking long source lines (they after all aren't made for that job). Another reason is that i find it looks better if everything fits into the line and isn't broken by the editor. For example having parameters of long function calls nicely aligned below each other and similar stuff.

Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
-1

We did a survey recently. Almost everyone uses vim inside an gnome-terminal, and if we do a vertical split the column count is 78 as standard font size and screen resolution 1280x1024.

So we all agreed to a coding standard with a column count of (around) 75 characters. It's ok.

pi.
  • 21,112
  • 8
  • 38
  • 59