一些有经验的程序员为什么要写前pressions这种方式? [英] Why do some experienced programmers write expressions this way?

查看:112
本文介绍了一些有经验的程序员为什么要写前pressions这种方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能显示的文件:结果
  如何检查等号? (0 == i)或(ⅰ== 0)的结果
  <一href=\"http://stackoverflow.com/questions/271561/why-does-one-often-see-null-variable-instead-of-variable-null-in-c\">Why做一件经常看到&ldquo;!=空可变的rdquo;的而不是&ldquo;!变量=空&rdquo;的在C#中?

我已经在这里和那里以及一些DirectX的code在看看一个奇怪的教程,发现许多有经验的C ++程序员编写以下列方式前pressions:

I've been having a look at an odd tutorial here and there as well as some DirectX code and noticed that many experienced C++ programmers write expressions in the following way:

(<constant> == <variable>)

而不是什么我的传统智慧似乎preFER:

rather than what my conventional wisdom seems to prefer:

(<variable> == <constant>)

例如。 如果(NULL == PTR),而不是如果(PTR == NULL)。我preFER第二替代方案中,如果没有其他原因选择前者,我的原因是变量似乎是前pression的接收端。

E.g. if (NULL == ptr) rather than if (ptr == NULL). I prefer the second alternative, if there are no other reasons for choosing the former, my reason being that the variable seems to be the "receiving" end of the expression.

但我怀疑前者是为了避免无意中使用分配常数变量的值 = ,而不是 == 。这是正确?

But I suspect the former is used to avoid inadvertently assigning the value of the constant to the variable by using = rather than ==. Would that be correct?

推荐答案

是的,这是正确的。这是检测的错字 = ,而不是 ==

Yes, that's correct. It's to detect the typo of = instead of ==.

这篇关于一些有经验的程序员为什么要写前pressions这种方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆