Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Poll: Line Length Limits?

 
Warren Dew
blacksmith
Ranch Hand
Posts: 1332
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'm getting bored waiting for Ilja's promised next post in the "code vs. design" thread, so I'd like input on another process/people/practices issue: line lengths.

1. Do you prefer to have a line length limit or not?

2. If yes, what are your minimum, maximum, and preferred line length limits?

3. Why?

I've noticed that my practice is fairly out of synch with other people on my current project, and I'm wondering if I should be more flexible....
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I'm getting bored waiting for Ilja's promised next post in the "code vs. design" thread, so I'd like input on another process/people/practices issue: line lengths.
Ilja is quite busy right now. I'm pretty confident, he'll come back at some time. Don't worry


1. Do you prefer to have a line length limit or not?
2. If yes, what are your minimum, maximum, and preferred line length limits?
3. Why?

Best practices (Sun conventions, etc) advocate for 80-characters lines. Personally, I don't really have a preference as long as the code is readable. In some cases, you might need to write lines longer than 80 characters. Trying to make my code fit within 80 characters lines is not really my primary concern. Sometimes it is not even possible due to the length of the method and class names that you have to use (third-party libraries, etc).

Again, you can use code beautifiers for doing that for you, but none of these tools has really satisfied me as of today. For instance, when I use Checkstyle, I usually deactivate LineLength during development and then when I'm done I reactivate it just to have a feeling of how much longer my lines are

The bottom line is that fixing the length of the lines in your code is more a matter of personal preference or corporate policy. I think there are many things that much more important to check regarding the quality of your code than check if the lines are too long or not.
[ May 26, 2004: Message edited by: Valentin Crettaz ]
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In writing, I've had to learn to make my lines as short as 60 characters. It's not very effective. Eighty characters is even a bit too short, given that today's high monitors and resolutions can present many more characters on a single line effectively. One hundred characters seems to work for many shops. One hundred twenty seems to be too many.

Yet every time I try to use the formatter to enforce a hard limit, even at 100 characters, there is always a line that ends up being formatted terribly. Having a stated guideline that developers can break (rarely and with good reason) seems to work better.

Instead of a hard number, my answer is "anything that doesn't force code readers to scroll horizontally." Once someone has to scroll to follow a method, you have temporary information loss, which makes code considerably harder to comprehend.

-j-
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We used to use 80 when my teams worked in Emacs. Now that we work in IntelliJ IDEA, we use 120. To a large extent, the right line length depends on the tools you use to work with the code.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends on the IDE and screen resolution. I run 1280 by whatever on a 21 inch monitor at work. I set the Eclipse formatter at 100 most of the time, set it up temporarily if it's splitting too much for me, set it back before I check code in.

I haven't used 80 since I moved off the mainframe. Actually used 72 there cause the editor reserved some columns for line numbers.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For me, it depends on the tools, too. Basically, I don't like to have to scroll horizontally when working on code.

At work, we finally agreed on 100 characters a line.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic