DEV Community

javinpaul
javinpaul

Posted on • Updated on

Does Coding with a Column Width of 80 Make Sense in 2024?

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided in this article.

One of the oldest coding practices is to keep line width 80, and many of us follow it blindly but have you ever thought about why we have this practice in the first place?

I believe it was to make your code more readable in the age of small monitors so that the whole content can fit on the screen, or it might have originated from the age of punch cards, which used to be 80 columns wide.

This sounds reasonable when we think about those old days but do you think this rule makes sense in 2024?

We are now living in the age where most of the developers have got large monitors, which can show up to 180 characters, ** don't this is wastage of precious monitor space?** It also makes your code unnecessarily long, then it is.

I first came to know about line wrapping at 80 while reading Oracle Code Conventions for the Java Programming Language, which was last revised on April 20, 1999, which under indentation says

4.1 Line Length\
Avoid lines longer than 80 characters, since they're not handled well by many terminals and tools.

Note: Examples for use in documentation should have a shorter line length-generally no more than 70 characters.

source: http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#248

If I understood correctly (I may be wrong), one goal of this rule is consistency. I used to think that 80 was silly, but being able to go through source code written by a dozen different teams over the last 7 years and not needing to re-size my window is a really nice thing. Consistent column width helps with the pace of reading code.

Since I mostly worked with large monitors, like LG 32MP58HQ-P 32-Inch IPS Monitor with Screen Split, I also realize that we are wasting lots of precious space. The consistent column width of 80 is simply too small.

I use 120 unless the project I work on already finalized a column width, in that case, I go for consistency.

Photo by Jefferson Santos on Unsplash

One more reason people give for still using a column with of 80 is that nowadays they are working with multiple files at once, mostly in VIM or in their IDEs like Eclipse or IntelliJ IDEA.

For example, if you use standard column width you can fit a couple of files across a reason and can compare them line by line, which I believe is a real benefit.

You can even do a three-way merge inspection on one screen without scrolling sideways. By the way, this should not be done at the cost of excessive wrapping.

I understand that consistent columns make it easier to scan and read through text but it doesn't matter whether it's 80 or 120.

On a closing note, I would say that consistency is nice and you must go for it but 80 or even 100 is too short.

Many developers could probably live with 120 or even 150 though. Our modern widescreen high definition LCD monitors can easily handle more.

It is much more readable than excessive wrapping because I find it much harder to read a wrapped line than just seeing the whole thing in one line. Of course, this is just preference and others will feel different.

So, what do you guys think, does this rule still hold or you have already moved on?

Other Programming Articles you may like
The 2024 Web Developer RoadMap
10 Data Structure and Algorithms Courses to Crack Programming Interview
10 Things Java Programmer Should Learn in 2024
The 2024 Software Architect RoadMap
10 Tools Every Java Developer Should Know
The 2024 Java Developer RoadMap
10 Frameworks Java and Web Developer should learn in 2024
10 Tips to become a better Java Developer in 2024
Top 5 Java Frameworks to Learn in 2024
Is ByteByteGo worth it?
10 Testing Libraries Every Java Developer Should Know

Thanks for reading this article so far till the end. If you like this article then please consider following me on medium (javinpaul). if you'd like to be notified of every new post don't forget to followjavarevisited on Twitter!

Top comments (20)

Collapse
 
anpos231 profile image
anpos231

TIL: That people have missed the real point of limiting line length to 80 characters.

The real point is that more than 80 characters makes lines appear very long and are much harder to read. Code that sticks to less than 80 characters is much easier to skip though.

PS: If you feel like you are wasting your monitor space then rotate it:
Vertical monitor setup

Collapse
 
dbanty profile image
Dylan Anthony

Heck yes, anyone who hasn’t tried out a vertical monitor should do so

Collapse
 
joshuamwolfe profile image
Joshua Wolfe

I wish I could get used to a vertical monitor, mine has a strange shadow. I think it's a reflection or something. It drives me batty.

Collapse
 
highcenburg profile image
Vicente G. Reyes

How would you do dual monitors on a mac mini?

Collapse
 
dorshinar profile image
Dor Shinar

I agree that most screens today can handle 120 or even more with ease, but I still use 80 characters since it makes it really easy to open two tabs (or more) in the same screen, something I find myself doing quite often.

Collapse
 
alexparra profile image
Alex Parra

Personally I completely disable forced wrapping and allow myself some long lines.
Scrolling horizontally on a Mac is a piece of cake and as natural as scrolling vertically.
I also feel it makes it much easier to scan the code.
Obviously this is a very personal preference and it should be a team decision as to what rules to abide by that suit everyone.

Collapse
 
mnayeem profile image
Nayeem Rahman

Are you sure it makes it easier to scan your code? We're not built to parse nested structures like AST's horizontally, especially when we can't look at it all at the same time. I think it helps to break lines at operators of lower precedence when it comes to readability.

Collapse
 
alexparra profile image
Alex Parra

Hi Nayeem!
I don’t mean i don’t break nested structures. I mean I don’t want to be pinned to a set length. Some lines make sense at 85 or 90 or whatever if it’s clear.
For example, I think blank lines are much more important at creating “separations” than imposing a strict line length.
And thorough indentation too.
Thanks for your reply.

Collapse
 
mt3o profile image
mt3o

Having two code windows side by side is awesome. Same thing goes for editor + browser, whether it's documentation or our js application we are working on.

Above that, IDE can be opened on a display with pivot set for portrait mode. Longer lines won't fit :)

There is one more reason for enforcement of colum width. It's to reduce the nesting levels. HTML with twelve or more nesting levels is well known to all those people who use html4 with tables. It's just difficult to find yourself in it, and yet I still see people doing 3 or 4 levels of nested loops, even more of nested anonymous functions.

Collapse
 
larsvonqualen profile image
Lars von Qualen

In traditional books the line length varies, but hovers around 60-75 characters per line. I like the way 80 characters makes it feel like i'm reading a book. That's my main reason for doing the column width of 80 thing.

Collapse
 
ryansmith profile image
Ryan Smith

I like 120 per line. Most lines fall around or under 80 characters, but in the event that some need to be a little longer it does not feel limiting.

I also do not open multiple code windows at once because it seems counterproductive to have a split focus. I work with one file at a time with keyboard shortcuts to navigate through them.

Collapse
 
voidjuneau profile image
Juneau Lim • Edited

I don't have much opinion on this since I'm a newbie.
However, because of GitHub, I'm forced to make it suit to 80, and It was a good practice to avoid unreadable code in my case.
I feel like I'm too good at obeying.

Collapse
 
nikoheikkila profile image
Niko Heikkilä

In my team we have ditched the hard line length rule and activated soft wrapping in editors. Mainly for two reasons:

  1. Macbook trackpads are comfortable enough scrolling code horizontally and vertically
  2. You can be more productive with the actual logic when you don't need to care about line length (the same goes for tabs vs. spaces argument)

And if, for some reason, we should enforce a hard line length then we would add the rule to our linter and the code would be automatically formatted to the width.

Collapse
 
jessyco profile image
Jessy • Edited

One reason to have a smaller column count is for code review/compare. I find it much more pleasant when you can just read without horizontal scrolling.

Collapse
 
mnayeem profile image
Nayeem Rahman • Edited

Some say it's to force us from having too many indentation layers and encourage refactoring when appropriate.

Collapse
 
anpos231 profile image
anpos231

True that! If you constantly find yourself writing lines longer than 80 characters then you should probably rethink what you're doing. I bet your code is a mess!

Collapse
 
mnayeem profile image
Nayeem Rahman • Edited

Well, not necessarily.

Long lines that are a result of long symbol names and a boilerplate-ridden language (note the author's Java background) can easily exceed that limit without actually becoming too complex.

I assume that's why, for example, Google enforces a bigger column limit for Java than the likes of JavaScript in its style guides.

Thread Thread
 
anpos231 profile image
anpos231 • Edited

I guess there is some truth to that, C code (especially object oriented C code) can end up with symbols that will easily take half of your 80 character limit (e.g. g_dbus_object_manager_client_new_for_bus_finish).

In such cases the GNU coding standards come in handy.

Collapse
 
pianomanfrazier profile image
Ryan Frazier

I have an extra wide curved monitor. I still code with 80 characters. I find very long lines hard to read as well.

The only time I use the full screen with my IDE is when I'm comparing diffs.

Collapse
 
masterperas profile image
Nuno Furtado

80 for me is a bit too low, i usually stick between 100-120

Some comments may only be visible to logged-in visitors. Sign in to view all comments.