[英]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 -关于可能原因的一些想法 -
Would be great if anyone can share如果有人能分享就太好了
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.