Possible Duplicate:
Is the 80 character limit still relevant in times of widescreen monitors?

I used to set a vertical line set at 80 characters in my text editor and then I added carriage returns if the lines got too long. I later increased the value to 135 characters. I started using word wrap and not giving myself a limit but tried to keep lines short if I could because it took a lot of time shortening my lines.

People at work use word wrap and don't give themselves a limit.. is this the correct way?

What are you meant to do ? Many thanks.

marked as duplicate by Arseni Mourzenko, gnat, Karl Bielefeldt, Ryathal, FrustratedWithFormsDesigner Oct 19 '12 at 15:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Opinions differ wildly on this matter. The best thing to do is to follow the same style as the rest of your team. It helps if the style is codified in a style guide so you can all argue about what's best in a productive way.

From my experience and from some random statistical data you can find on the Internet, the best is to keep lines at a maximum of 120 characters. That is about how much is comfortable for a human to read in a single line and also it does not require horizontal scrolling on most displays today.

I am strongly recommending to anyone to put and respect a limit because not all editors have a word-wrap feature and not all programmers enable word-wrap in their IDEs. In fact I do not personally know anyone who uses word-wrap in source code.

Word wrap can also be confusing when the code suddenly breaks the line in places that would lead to errors if there would be real new line at that point.

It depends on how your source code will be used/by whom.

If it will be printed with monospace font or shown through terminal use 80 characters.

If others with smaller monitors will look at it, use some limit to acomodate them (eg 80, but it can be more, but 80 is safe).

Another point of view, try to not use so long lines (sometimes it is unavoidable, often it is avoidable (and sometimes avoiding it is not worth it)). Long lines are from: 1) too deep indentation (introduce functions) 2) too much done on one line 3) method chaining 4) too much parameters for one function 5) too long indentifiers

all of them are code smells (at least for someone).

if method declaration gets too long (without having enormous ammount of parameters), puting one parameter per line can be much more readable than wrapped line or scrolling to read it.

It depends on your team norms. Some people want the 80 character limit, some could care less.

The focus though is on readability. If code goes off the screen it tends to be unreadable. If it wraps around, that tends to be unreadable too. It's often better to refactor the code to simply not be too long.

What's "too long"? Most places I've been have had the same monitors, and the same IDEs with the same fonts. Baring some team norm, I would work off of "if your code goes off your standard screen using a full screen IDE with the standard font and configuration... then it's too long."

  • If some people want the limit, and some could care less, then it seems charitable to apply the limit. I don't think there are that many people who really, really, really want long lines and find shorter lines to be a problem. Agreed re. your IDE rule, except that I'd say "window" instead of "screen" -- many people want multiple windows side by side. – TextGeek Dec 21 '17 at 15:26

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