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?
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....
Joined: Aug 26, 2001
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 ]
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.
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.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Joined: Jul 11, 2001
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.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus