c ++ styleguide:为什么在左侧有非左值? [英] c++ styleguide: why to have non-lvalues on the left side?
问题描述
在一个 C ++编码风格指南中,
我发现了一个特别的建议(第41页,建议53):
左侧始终有非左值(
0 ==
$ b <$
p>我不知道这是什么好?是否坚持这种做法?
我不是,我不知道他为什么是一个好的做法。我可以想到的唯一的优势是,将避免错误的比较( if(foo = 0){}
对比 if你有什么其他想法为什么我应该使用它吗?
是的,你猜对了。这是好的,老的 Yoda条件 !!!
In one C++ coding style guide, I found one particular recommendation (page 41, recommendation number 53):
Always have non-lvalues on the left side (
0 == i
instead ofi == 0
).
And I don't uderstand what is this good for? Are to sticking to this practice?
I'm not and I don't know why is his a good practice. The only advantage I can think of is that is will avoid mistaking an unintentional assignment with a comparison (if (foo = 0){}
versus if (foo == 0){}
)
Have you got any other ideas why should I use it?
Yes, you guessed it right. It's the good, old Yoda condition!!!
这篇关于c ++ styleguide:为什么在左侧有非左值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!