DEV Community

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

javinpaul on June 28, 2019

Disclosure: This post includes affiliate links; I may receive compensation if you purchase products or services from the different links provided i...
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