DEV Community

Discussion on: Maximum line length in your code

Collapse
 
justinctlam profile image
Justin Lam • Edited

Just because machines and tooling can break down constraints, e.g. bigger monitor, better IDEs, etc. that doesn't mean we should neglect the human factor. I think there is a reason why websites, books, or other heavy text mediums have a line length constraint and I think it is because it's easier for humans to read.

baymard.com/blog/line-length-reada...

Too wide – if a line of text is too long the reader’s eyes will have a hard time focusing on the text. This is because the line length makes it difficult to gauge where the line starts and ends. Furthermore it can be difficult to continue onto the correct line in large blocks of text.

Too narrow – if a line is too short the eye will have to travel back too often, breaking the reader’s rhythm. Too short lines also tend to stress readers, making them begin on the next line before finishing the current one (hence skipping potentially important words).

Every now and then, I think it's ok to break the line length rule by a few characters but you should also consider if there is a better way to shorten the long line length.

Collapse
 
sorashi profile image
Dennis Prazak • Edited

Nice comment and blog post, but I don't think this is too relevant to code. The blog post is about research in UX, especially continuous text. I personally don't usually read code like a book, I skim through it looking for the context I need. That's why I don't like having function declarations span multiple lines. I typically look for the function name. If I require some more info, I look further right on the line. That's why their recommendation of 50-75 characters per line does not apply to code, IMO. That being said, I like a line width of 120 for code, excluding comments, which I like without a line width limit.