在源文件中强制执行固定文本宽度
在源代码文件中应该如何严格地遵守固定文本宽度?更具体地说,您是否始终遵守代码的 80 个字符限制以及注释的 100 或 120 个字符限制?有时,我的代码中有些行我不愿意引入换行符,因为它会破坏一致性或降低周围代码的可读性。在这些情况下,您会自行决定,还是始终选择遵守文本宽度?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我以前也遇到过这些情况。虽然我使用 80 个字符作为指导原则,但我对一致性给予更高的优先级,因此,如果保持清晰度,我可以随意超出限制。
我可以接受超过限制的原因是,现在大多数人(至少与我一起工作的人)都有编辑器/屏幕,这些编辑器/屏幕可以轻松显示超过 100 个字符,因此超过 80 个字符不会妨碍代码的可读性。
虽然限制通常有助于保持代码的可读性,但我发现如果我总是尝试维持限制,那么,就像您所说的那样,代码的流程以及因此的可读性都会被破坏。
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.
这取决于您为何寻求实施限制?
该代码是您一个人的,还是与许多其他人共享的?您是否正在创建可供一个人、十几个人、数百人查看和增强的源代码?使用/观看的人越多,一致性就越好。
当然,你也为不限制提出了很好的论据......
我的两分钱。
It would depend on why you are seeking to enforce a limit?
Is the code yours alone, or is it shared with many others? Are you creating source that will be viewed and augmented by one other person, a dozen people, hundreds? The more people who are using/viewing, the better it is to have uniformity.
Of course, you also make a good argument for not limiting...
My two cents.