Join the DZone community and get the full member experience.Join For Free
Bring content to any platform with the open-source BloomReach CMS. Try for free.
I tend to wrap most code I write at 80 columns. Many programmers I interact with (especially those contributing to my projects) don’t really see the point of that, so I here’s why I do it:
1. It works well with UNIX tools like less, grep etc. at standard terminal sizes. Sure, you can resize your terminal emulator, so I guess it’s not a very strong argument in this day and age.
2. It works well with pretty much every diff and review tool. That’s a better argument, because many of these tools have some kind of line limit, and 80 is certainly the lowest common denominator that works well everywhere.
3. Most lines are shorter than 80 columns anyway, this rule is mostly about how to deal with exceptionally long lines. Java code is a notable exception here, wrapping that at 80 columns is pretty hard. I’d still argue for a line length limit in Java code, 100 or 120 columns seems to be popular.
4. From my experience, short lines result in more readable code overall. Less nested expressions and more (reasonably named) temporary variables always appear to make things easier to follow.
5. You need less horizontal space for your editor. So you can show other windows (browser, terminal, other files, …) next to it.
I came up with only one downside of wrapping at 80 columns: You have to think about how to wrap long lines, or preferably refactor them into multiple shorter lines. It’s definitely some extra effort, but as I noted above, I strongly believe this aids the overall readability of the code, so I’d say it’s time well spent.
Published at DZone with permission of Felix Dahlke , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.