Take the 2-minute tour ×
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.

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.

share|improve this question

marked as duplicate by MainMa, 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.

    
If I read someone else's code, I usually style it as it is convenient to me while reading. After when I'm finished depending on the situation I might save or undo those changes. –  superM Oct 19 '12 at 14:03
1  
add comment

4 Answers 4

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

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