The Enterprise Line Is Too Short
Sun's / Oracle's programming style guide as well as the JavaRanch and many corporate "enterprise" style guides limit the line width in an editor. 80 characters are still a popular setting.
All IDEs can be configured to honor the settings, but too short line width usually leads to awful looking code.
Even worse. Developers are tempted to use cryptic naming conventions to conform with short line width, what negatively impacts the maintainability.
The explanation of the limitations are sometimes funny. Usually such conventions are explained with printability. The real reason are typewriters ...from 1961.
See you at Java EE Workshops at MUC Airport!
You are wrong with the reason!
The reason is much older. IBM punchen cards from 1928!
Therefor the line width was 80 as well because the first programs were written on punched cards.
Posted by Simon Martinelli on March 05, 2014 at 12:46 PM CET #
A modern reason is to be able to have two pieces of code side by side on your screen (three-way merge, review).
Besides that, if you have an appropriate low nesting depth, you don't need more than 80, or maybe 120, chars.
Posted by Oliver on March 05, 2014 at 04:23 PM CET #
As long as you can fit two pages next to each other, as Oliver said, you are fine. We found that anything less than 110 chars is good on HD res screens. The worst case is _no_ line limit.
If you feel really crazy, suggest your peers a two space indentation. That makes a huge difference in usable screen estate. It's just not worth to start a war about it (and most java devs will).
I tend to agree with google on that: http://google-styleguide.googlecode.com/svn/trunk/javaguide.html
Posted by Roman Ataman on March 05, 2014 at 05:47 PM CET #
IMHO 80 characters are crazy, but 120 are sufficient.
I think you other (team) problems if you need a line width limits :-)
thanks for commenting!
Posted by Adam Bien on March 05, 2014 at 07:38 PM CET #
I personally tend to use between 80 and 120 characters on a line. No more.
I feel wider lines forces the reader's eyes to travel long distances when searching for a specific code.
This might be relevant: http://en.wikipedia.org/wiki/Eye_movements_in_reading
BTW, IMHO the small font on the comments on this blog provoke long lines, which are unpleasant to read :-) <http://mikeyanderson.com/optimal_characters_per_line>
Comparing two files of code side by side is a plus. Of course, I've been asking my employer for years for three monitors: one for source code, one for application/browser and one for debugger/logs. XD
Posted by Arturo Tena on March 06, 2014 at 03:02 AM CET #
I'm not advocating wide lines. Lines should be as short as possible without crippling the identifier's names.
Dogmatic max line width restrictions force developers to use cryptic names and too short method names.
But: if you are forced to use short identifier names, you could use JavaDoc to provide more context :-)
thanks for commenting and good luck with the monitors. If everything fails -> CRTs should be easy to get :-)
Posted by Adam Bien on March 06, 2014 at 04:25 AM CET #
One reason most probably is readability. The longer the line the more effort to follow the line break back to the beginning of the next line.
The monitor/typewriter/punchcard comparison is as poor as punchcards are nowadays. Otherwise larger sheets of paper would have made newspapers write longer lines instead of multi column layout.
If your self explanatory names are using that much of space I ask you to think about if they might self explain too much. Try refactoring. Same or worse for starting off at excessive indentation levels.
Code with long lines is not easier for everyone, do you want those readers finding you bugs or not?
Posted by Bernhard on March 06, 2014 at 11:26 AM CET #
Origin yes: typewriters 8 inch, 80 characters. Then printers, later monitors. How much we hate cramping code into 80 chars per line, I still like reading code on an ebook.
Posted by Joop on March 06, 2014 at 02:03 PM CET #
Fully agree, 80 char makes no sense.
The "average" Developer has 2 Full-HD monitors, you only need a 80 char limit if you're planning on debugging your code on your Mobile Phone!
Posted by Luccas on March 06, 2014 at 05:18 PM CET #