Hacker News new | ask | show | jobs
by eikenberry 583 days ago
IMO 120 is the extreme limit but a good limit. Anything higher than 120 is to long and, personally, I'd ask for that to be fixed in a code review.
2 comments

120 is way too small. IMO 180 is a good limit. We're not on 800x600 screens anymore
Lots of people are using split screen editors though. Tbh if you are butting up against the 120 limit, you're probably doing something wrong and could easily break the lines, or use less levels of indentation.
Over 120 and most likely something is wrong with the code. That many levels of indentation usually means that code's cyclomatic complexity is off the charts and is in desperate need of refactoring. It could indicate bad naming practices (to long) which also should trigger refactoring. This is all to say it is more about what long lines say about the code than anything to do with the display.

Some languages are just naturally worse at this (eg. Java), so there is always some flexibility. But for most languages that don't have multiple levels of indentation by default and the custom of overly long names, 120 is more than enough to be a good guidepost.

I have three 4K monitors and use a small font and think 180 is way too large.

Long lines are less readable and I want to have several terminal panes or editor windows side by side.

I just bought an ultrawide, and I just checked to see how wide my lines are in my code editor. 350 characters.

When I'm coding for myself, I use all of that at times. I love that there are some things I no longer have to break onto multiple lines any longer.

Also, if you have a ton of nested loops etc, then you don't end up with that problem where you can only see the first few characters of the deepest lines.

In the space you use for editing a single file I can fit four 80-column source files (which I do, I also have a giant monitor).

Also, excessive nesting is almost always a code smell.

I think the issue with a very long line is akin to writing without punctuation because code is usually much more information dense than prose it becomes hard to follow what it is supposed to mean than if there were pauses for you to consider points in isolation but otherwise I don't see a problem with long lines if you have for example some very long silly OOP getter chain which is essentially one expression as for tons of nested blocks the general argument is it's a hint that your single unit of base indentation is doing too much and there is possibly something to be done about it though like everything it is usually taken to a unhelpful extreme.
I suspect nested loops going that deep are very likely to be a design problem.
Loops nested deep enough that you need an ultrawide to avoid truncated lines!?
The idea of 350 characters worth of nested loops leaves me speechless.