Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

My editor has a default of 80 characters, and I'm wondering if this is too small (or too large).

  • How many characters wide should the code be?
  • How wide is yours?
  • Did you ever even notice that your editor has this setting?
share|improve this question
Too small...... – tvanfosson Nov 21 '10 at 23:58
10  
@tvanfosson - That's what she said. – ChaosPandion Nov 22 '10 at 0:33
1  
I've been using NetBeans for nearly 2 years now and this is the first time I noticed that red line going down the middle since reading this question lol. It's 80 characters aswell. – Jonny Nov 22 '10 at 1:09
The corollary question for our younger programmers is: do you know why 80 is the default? – Barry Brown Nov 22 '10 at 1:20

closed as not constructive by ChrisF Feb 14 '12 at 8:41

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

9 Answers

up vote 7 down vote accepted

Most people use either 80 or 72/73 character width. Some use up to a 100, but that already sometimes presents a problem with printing. Besides, long lines are (at least to me) hard to look at. I prefer vertical layout of code, not "infinite" rows ...
There is a reason why newspapers are printed in columns :-)

Mine is 72.

Btw, if you search SO on this topic you'll find somewhere a link describing the results of a research some time ago that showed that most publishers for example, also use a (my memory is somewhat vague on this, but maybe) 66 char. width per page. It was shown to be easiest to read.

share|improve this answer
5  
I can't remember the last time I printed any source. It's been several years at least. – the Tin Man Nov 22 '10 at 0:22
I printed out reams of code when I was trying to understand the Ghostscript driver API. I found I had to reference 7 different sets of code simultaneously, and printing it out helped immensely. – greyfade Nov 22 '10 at 0:33
My first though was: This question, again? I'm probably thinking of the question on SO. I used to hope that the increase in screen resolution would lead to an increase in the typical width of code. Now, I realize that it is much easier to understand if it doesn't span past this approximate width. One line of code spanning a wide screen is no big deal, but if all the code is like this it's a pain to read. This may result in more vertical scrolling, but there should be plenty of room to have 2 views of the same file, side by side. – George Marian Nov 22 '10 at 1:08
1  
@Rook: I went to school for design for a year before switching into a more development-oriented major. It's seen as common knowledge in typography that line lengths should be kept around 60 characters for maximum legibility. Actually, a lot of what I learned about general legibility of type backs up pretty much all of my opinions about code legibility. – Jon Purdy Nov 22 '10 at 6:06
1  
@rmx: Oh, I agree that code and body text read very differently, but I think there are some guidelines that are pretty much universal, such as fairly liberal use of whitespace. Mostly I just try to approximate mathematical typesetting conventions. I've also been influenced by the screenplay format, since screenplays are perhaps the only non-programming document that are consistently typeset in a fixed-width font. – Jon Purdy Nov 22 '10 at 20:09
show 1 more comment

I use an IDE that isn't terminal centric. I try to maximize the screen real estate of the editor window (on a 1600x1200 screen) and simply avoid horizontal scrolling. I also don't try to fill up each line, but will use returns at logical points to make the code more readable even when the code might fit on a single line. For example, when using a fluent style with LINQ:

var prices = context.Foos
                    .Where( f => f.Name == "Bar" )
                    .Select( f => f.Price );

Readability, not screen width, ought to be your biggest concern. Having said that, limiting your line length to the minimum of the people on your team and making sure that people on your team have a reasonable minimum line length is a really good idea. The last thing you want is people reformatting code (and checking it in) just so they can read it easily.

share|improve this answer
1  
why the extra space padding inside parenthesis? – Kugel Nov 22 '10 at 1:49
2  
@Kugel - more readable. – tvanfosson Nov 22 '10 at 2:20
1  
Indentation which increases readability sometimes decrease maintainability (as in this example, if you change the name of prices you probably need to realign lots of code lines). So I try to aim for most readability without sacrificing any (or very little) maintainability. – gablin Nov 22 '10 at 12:45

I've seen in "Best Practices" lists and books that < 80 is correct.

My editors and screens support a lot more than that, and I find 80 columns very restricting so I'll go past that. I do try to stay with 132 though, as I find lines beyond that to be unwieldy.

share|improve this answer

There is no, one, right answer to this issue. I use 120 characters in my IDE, but 80 is an old standby. If your code is consistently longer than your display width it could mean the width is too narrow, or your code needs some attention. Keeping line lengths sane is important for code readability. Some will object to anything above 80 because of issues with printing code, but I respond to those concerns by asking why anyone is printing code on paper that isn't going into a book on programming.

Regardless of the width you choose, it is more important to make sure your code makes sense and that you aren't cramming more than what's necessary into a single line. If you have lots of long lines of code you may be "doing it wrong." If you can justify a line of code that is 80 characters wide or 120 characters wide then go for it.

share|improve this answer

For me variable width fonts are much easer to read than fixed width fonts.

With my current settings there's room for about 240 characters in the width of my editor. It varies a bit depending on how wide I want other windows to be.

share|improve this answer
240 may be fine for you, but what happens when you give it to some coleague to use it? – Rook Nov 22 '10 at 0:41
@Rook: Well, I rarerly use the full width, partly because of the reason that you mention, but that is how wide my editor is. – Guffa Nov 22 '10 at 1:00
I tend to stick to 80 characters. I find that a side effect is having much more room for other windows. So in VS, rather than just having code on the left and solution explorer on the right, I might have in between them R#'s todo explorer or the object browser, and still be able to see all of my code. – rmx Nov 22 '10 at 13:26

80 characters. I programmed a custom key command for Emacs that would resize the window to 160 characters so I could split the screen without having to take my hands off the keyboard.

Then I put it somewhere on one of my monitors and I have a couple terminals on another window. Along with Firefox for google/stuff to read during a long compile. I then also have a music player up on the same screen.

The more things I can see without having to use Alt+Tab or a mouse the better.

share|improve this answer

Discarding the margins both left and right, the central column of this very page, programmers.stackexchange.com appears to be 80 characters wide. I guess the reason behind that could be easy on eyes or something similar. Or, it could be because text based programs normally use 80 character width.

share|improve this answer
2  
Your second row is 102 chars wide. – Kugel Nov 22 '10 at 1:46
:) It is. But stackoverflow.com/questions/95575/… and stackoverflow.com/questions/110928/… have some decent discussions on why it is best kept at 80 though that is not a carved on stone. The discussions make me think if this question could be a possible repeat of those two questions. – vpit3833 Nov 22 '10 at 2:54
Well, this is programmers.stackexchange.com, and I didn't see any questions about this here [after searching], so I asked. Although, I didn't search SO... – muntoo Nov 24 '10 at 6:44
@muntoo: I hope those discussions answer your question in ways that complement the accepted answer here – vpit3833 Nov 24 '10 at 9:00

This dates back to the quaint old days of paper printout.

Seriously, it's easier to just get some more screens. (They only come in wide these days.)

<I'm not really this fogey>

You try getting green bar paper for your 132 column printer. It ain't as cheap as the 80 column greenbar. (And you can't get 200 column greenbar, so you can't print that code.)

</I'm not really this fogey>

Old fogies (like me) refer to greenbar, which is paper with preprinted green bars on alternate 3-lines. Classy greenbar even discreetly numbered the lines. The paper has tractor feed holes on the edges, for the printer, and is in continuous sheets, with perforations every page.

The bars aren't necessarily green, they can also be yellow, and I've seen an orange-ey yellow.

The edges of the bar are 100% saturation, and the fill is about 25%.

share|improve this answer
Don't forget the paper with black bars with holes beaten through it because the tractor drive tore the feed holes out when the paper got stuck in the box for some stupid reason, and nobody noticed. It's similar to plotters drilling holes through a sheet when the page feed fails. – the Tin Man Nov 22 '10 at 5:30

Older compilers preferred 71 charcters so that is a good thumb rule.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.