Why code lines still should not exceed 79 characters

I hate long code lines. I hate them with passion.

You might think that in the modern era of programming everybody has a big ass monitor with loads of horizontal space for the editor. Unfortunately you are wrong. What is the point of having a big monitor if you have to make the editor cover the whole screen? I have two 24-inch monitors, but I have one of them rotated 90 degrees, which makes the resolution 1200×1920. 1200 pixels is enough for a pretty wide editor window, but I always have two editor windows open side by side, which makes the editor windows 600×1920 pixels and that is about 2x79x120 in visible characters.

I am also old school and use terminal windows, which, as you can guess, are about 80 characters wide. It helps a lot if the code, does not wrap inside the terminal window when using version control commands from the terminal.

OK, so far the reasons have been pretty much about the environment and a lot of people have environments that support long lines easily. However, something that is universally bad about long lines is the way they affect the readability of code. Long lines make the code harder to read. If you have to turn your head when reading code, digesting the code will be much harder.

Code is read more often than it is written, so writing elegant code should be the goal of every single programmer. It is much easier to get a complete picture of the code, when the lines do not run forever. There is also a reason why books are shaped the way they are. Who would like to read a book that has lines over 150 characters long?

People post questions to stackoverflow.com and sometimes include source code related to their questions, which is really useful. However, the code window is only 79 characters wide and there will be a horizontal scroll bar, when the code does not fit in the window. That is really annoying. Trying to figure out what is happening in the code when you cannot see full lines of the code is really hard. I am not blaming stackoverflow.com, but I am blaming the programmers, who post sample code that have long lines.

Sometimes code needs to be printed. Not that often, but there are good reasons to do that. If code looks like crap on screen, it will look even worse on paper especially with those long lines wrapped in the printed version.

Every time I see long lines, my respect for the author of the code drops a little. I do not think there are any excuses for writing long lines. Every programming language I have used supports splitting code to multiple lines. Some languages do it better than others, but the language is not the problem.

The problem might be the editors that most people use to write code. Usually when I see long lines, the code has been written in either Visual Studio, Eclipse or Xcode. People that use those IDEs have their environment full-screen, which makes the editor window quite wide. The template code that IDE will generate is usually terrible and people just copy ‘n paste that crap. Editors also indent lines differently when you split them, or do not have automatic indentation support for lines that where split. This might cause the writer of the code to avoid splitting, because it will require pressing the tab 6 times to get to the correct indentation point. Configure your editor to do this for you. (Or even better, use a real editor)

  • Share/Bookmark

Trackbacks / Pingbacks

  1. Getting the miliseconds from now to the next midday | CL-UAT

Leave a Reply