coding-styletext-width

Enforcing fixed text width in source files


How strictly should one should stick to a fixed text width in source code files? More specifically, do you always abide by the 80-character limit for code and the 100- or 120-character limit for comments? Sometimes there are lines in my code in which I am hesitant to introduce a line break since it would disrupt the uniformity or reduce the legibility of the surrounding code. Do you use your discretion in these cases, or always choose to abide by the text width?


Solution

  • I've run into these situations before as well. While I use the 80 characters as a guideline, I give uniformity a higher priority, so I feel free to exceed the limit if it maintains clarity.

    The reason I'm okay with exceeding the limit is that most people these days (at least people I work with) have editors / screens which are easily capable of displaying well over 100 chars, so exceeding 80 does not impede the readability of the code.

    While the limit generally helps to keep code readable, I find that if I always try to maintain the limit, then, like you said, the flow of the code, and therefore it's readability, is disrupted.