代码边距有标准吗?

发布于 2024-08-09 18:22:16 字数 716 浏览 2 评论 0原文

类似的问题

编码时,您要格式化多少列?
什么是每行代码合理的最大字符数?
人们仍然遵循 80 列规则吗?
80 列限制还有用吗?


通过代码边距,我是指指导特定代码行长度的行。不同的 IDE 对于该设备有不同的语言,我相信 Visual Studio 称它们为“排水沟”。

话虽如此,长度代码边距是否有特定的标准?我的 IDE(Netbeans)默认为 80,但我想知道该默认值是否有任何规律或原因。

Similar Questions

While coding, how many columns do you format for?

What is a sensible maximum number of characters per line of code?

Do people still live by the 80 column rule?

The 80 column limit, still useful?


By code margins I am referring to the lines that guide how long a particular line of code is. Different IDEs have different language for this device, I believe Visual Studio calls them 'gutters'.

That being said, is there a particular standard to the length code margins? My IDE (Netbeans) has 80 by default but I was wondering if there was any rhyme or reason to that default.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

☆獨立☆ 2024-08-16 18:22:16

我们使用 80 列80 多年来,谢谢IBM 的打孔卡。它是 PC 上的默认文本模式,也是终端窗口的默认大小。将行数保持在 80 列限制以下意味着它们可以在这些环境中显示而无需换行。

我相信 Visual Studio 默认值为 120 列(尽管 可以更改),在我看来,考虑到 LongVerboseDotNetCompliant 命名约定,这更有意义。在 IDE 中工作时,最大化它是很常见的,因此 80 列的限制往往会浪费空间,除非您打开了很多侧边栏。

我碰巧更喜欢 72(在编写 HTML、Python 等时),它允许我的代码适合标准终端,并有空间打开行号。

We've been using 80 columns for over 80 years, thanks to IBM's punch cards. It's the default text mode on a PC, and it's the default size of a terminal window. Keeping your lines under the 80 column limit means they can be displayed without wrapping in those environments.

I believe the Visual Studio default is 120 columns (although that can be changed), which in my opinion makes more sense given the LongVerboseDotNetCompliant naming conventions. When working in an IDE, it's pretty common to maximize it, so an 80-column limit tends to waste space unless you have a lot of sidebars open.

I happen to prefer 72 (when writing HTML, Python, etc.), which allows my code to fit in a standard terminal with room to turn on line numbers.

蘸点软妹酱 2024-08-16 18:22:16

通常设置为 80,因为这是终端的标准字符宽度,允许从命令行轻松查看代码。

它在像 python 这样的语言中仍然很流行,其中空格很重要,并且通过 CLI 与解释器一起工作很常见,但在其他语言中变得不那么标准。

This is normally set to 80 because this is the standard width of a terminal in characters, allowing code to be easily viewed from the command line.

It's still popular in languages like python where whitespace is important and it's common to work with the interpreter via a CLI, but is becoming less standard in other languages.

难得心□动 2024-08-16 18:22:16

取决于:
1) 是否要将代码打印到纸上(例如,用于代码审查时的讲义);
2) 检查或维护代码的其他人将使用什么环境。

80 列是通用标准(如前所述),因此适合该宽度的代码可以在现有的任何打印机上打印。同样,任何现有编辑器都可以查看和编辑 80 列代码,而无需处理换行。

另一方面,如果您知道您的团队将始终使用宽屏 IDE 编辑器和横向模式打印,则 120 列 是合理的最大代码宽度。

您还应该使用合理的缩进宽度,例如 3 到 5 个空格。 2 个空格通常太小,无法在长方法中看到对齐的语句(但对于 SQL 等语言中的小方法来说还可以),而 8 个空格则不必要地占用大量水平空间。

Depends on:
1) whether you're going to print the code onto paper (e.g, for handouts at code reviews);
2) what environment anyone else who examines or maintains the code will use.

80 columns is the universal standard (as stated prevously), so code that fits within that width can be printed on any printer in existence. Likewise, 80-column code can be viewed and edited by any editor in existence without having to deal with line wrapping.

On the other hand, if you know your team is always going to be using widescreen IDE editors and landscape-mode printing, 120 columns is a reasonable code width maximum.

You should also use a reasonable indentation width, such as 3 to 5 spaces. 2 spaces is usually too small to see aligned statements in long methods (but okay for small methods in languages like SQL), while 8 spaces uses up quite a lot of horizontal real estate unnecessarily.

没有心的人 2024-08-16 18:22:16

除了与功能较差的环境兼容之外,80 列还有一个额外的优点:以半智能方式分解为较短行的长语句通常比单个 120 列行更容易阅读,即使环境可以显示该内容不包裹它。

80 columns has an additional advantage, other than compatibility with less capable environments: long statements that are broken up into shorter lines in a semi-intelligent manner are generally easy to read than a single 120-column line, even if the environment can display that without wrapping it.

感情旳空白 2024-08-16 18:22:16

我见过有人使用长列(120 或更多),但出于上述原因和其他原因,我坚持使用 80 列,例如:

  • 易于代码审查 - 通过打印或使用工具 (代码协作者)
  • 在 17 英寸或以上的显示器上分屏 两个并排的代码窗口。
    side(例如 header 和 cpp)允许更轻松的编码。
  • 避免使用太多嵌套代码,它有助于保持逻辑简单!
  • 由于名称简短、更简单、逻辑更简单等,有助于编写更简洁、更简单的代码。

因此,这一切都取决于您是否单独工作以及如何使用所有代码 - 由其他人阅读或维护等。

I have seen people using long (120 or more) columns, but I stick to 80 columns for reasons explained above and others such as:

  • Ease of code review - either via printing or using tool (Code Collaborator)
  • Split screen on 17" or above monitors. Two code windows side by
    side (e.g. header and cpp) allows easier coding.
  • Avoids going to too many nested code, it helps keep logic simple!
  • Helps writes more concise and simpler code, due to short and simpler names, easier logic etc.

So, it all depends on whether you are working alone and how all the code will be consumed - read or maintained by others etc.

神爱温柔 2024-08-16 18:22:16

我通常以一些不幸的人能够在 1024x768 上查看的尺寸进行编码

I typically code at a size that some unlucky individual could be able to view it on 1024x768

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文