简体   繁体   English

影响编程风格的因素

[英]Factors influencing programming style

It is common to see programmers follow tacit style guidelines when writing out programs.在编写程序时,通常会看到程序员遵循默认的风格准则。 For instance, in most languages I have dealt with, we invariably always write if x < 5 instead of if 5 > x although both are permissible expressions by the underlying grammar.例如,在我处理过的大多数语言中,我们总是写if x < 5而不是if 5 > x ,尽管两者都是底层语法允许的表达式。

Does anyone have suggestions for what could have caused these biases to be picked up by us when we write these expressions?有没有人对我们在编写这些表达式时可能导致我们发现这些偏见的原因提出建议?

Some thoughts on possible reasons -关于可能原因的一些想法 -

  • It could have been a constraint posed in the grammar of an early programming language like Scheme, Algol, or even Assembly?它可能是早期编程语言(如 Scheme、Algol 甚至是 Assembly)的语法中的约束?
  • It could have been a rule enforced by some early style-checkers?这可能是一些早期风格检查员强制执行的规则?
  • Any other?任何其他?

    Would be great if anyone can share如果有人能分享就太好了

  • insights tying such preferences to practices from early days of programming, or even academic references discussing such preferences.将这些偏好与编程早期的实践联系起来的见解,甚至是讨论这些偏好的学术参考。
  • help provide more examples of such preferences which they may subscribe to/have encountered.帮助提供他们可能订阅/遇到的此类偏好的更多示例。

  • I'm almost certainly checking the value of x , not checking the value of 5 .我几乎肯定会检查x的值,而不是检查5的值。 My thought process is therefore going to be "if x is greater than 5...".因此,我的思考过程将是“如果 x 大于 5……”。

    And therefore I write if x > 5 and not if 5 < x .因此我写if x > 5而不是if 5 < x

    In short, I write the way I think.简而言之,我按照我的想法写。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM