There are lots of websites or blogs said that we should keep 80 characters per line in our program since it is relatively to display in some console environment.
However, I found that it is very hard to keep this practice in Java. When we write Java code, we write a function in a class, it requires us to do some indentation already, let alone to add a few if-else statements inside the function.
Apart from that, we always keep call functions in a object. Such kind of behavior make that it is hard to make 80 characters per line.
Wrapping the line is a method, but it decrease the readability of the code.
I am not a professional java programmer. Would you still follow this rule when writing Java? or is there common practice on the indentation of java?
The limit of the line length in 70–80 characters may well have originated from various technical limitations of various equipment. The American teletypewriters could type only 72 CPL, while the British ones even less, 70 CPL. In the era of typewriters, most designs of the typewriter carriage were limited to 80–90 CPL.
Other code standards in the list also recommend that the limit should be ignored when that makes the code more readable. A common example is a long URL that's pasted into the source code. Aim for a maximum length of around 80 to 100 characters per line, but you don't have to follow it religiously.
If there's any accepted industry standard for maximum line width, it's 80 characters. I've used that maximum for years, and it's a good maximum. Like all other programmers, other people's code annoys me. The most common annoyance is that people write too wide code.
Ideally, one line of code is a unit element that means or performs something specific – a part of a sentence if you will. It is generally agreed that the ideal length for a line of code is from 80 to 100 characters.
80 character line length restrictions made sense when we dealt with paper punch cards and small monitors. I think it makes little sense now that we read code on wider monitors.
I find that nesting and methods have little effect on readability. If I see nesting that's too deep, it's a suggestion that the cyclomatic complexity of my method is too high - time to decompose.
I don't want to scroll back and forth, but I find that 120 characters is manageable.
It depends on your environment/team/ways of working. Since all of us have widescreens on our desks we want to use as much screen estate as possible. We have 120 characters and it has worked well for us.
If you are having problems with always filling the 120 characters width I'd say you should look over your code, perhaps some refactoring is in place.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With