本文介绍了if(false == condition)。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到来自某人早期工作的代码,它包含很多行,例如

I have received code from someone working earlier on it, and it contains a lot of lines like

while(false==find && false == err && k<kmax)
if(true==refract(ep1,ep2,n1,RI_blood, RI_collagen))

,我最喜欢的行是

if(false == (ret_s<0))

另一个代码做得很好,但是这些具有这些奇怪条件的行正在扔我,我不知道为什么他们这样做。

The other code is done really well, documented just fine, but these lines with these odd conditions are throwing me off, and I wonder why they are done that way.

特别是 false ==(ret_s< ; 0)是完全混乱,你需要读这行三次,以了解他们想要什么。

Especially that false==(ret_s<0) is completely confusing, and you kind of need to read that line like three times to understand what they want there.

一个常见的编程风格,我不明白的推理,或者只是坏的风格?

Is this a common programming style, don't I understand the reasoning for that, or is that just bad style?

编辑:我不觉得这是类似于if对象== NULL)vs if(NULL == object),因为这不是关于意外分配,而是关于obfuscated if子句...

I don't feel this is similar to if(object==NULL) vs if(NULL==object), since this isn't about accidental assigning but about obfuscated if clauses...

推荐答案

否。

人们喜欢用 true false 显式比较布尔值,即使结果是完全相同的布尔值。逻辑可能是,通过使代码更难阅读和更令人惊讶,人们会更加努力地思考它,并对它的行为做更少的假设。

Some people like to explicitly compare booleans with true or false, even though the result is exactly the same boolean value. The logic is presumably that, by making the code harder to read and more surprising, people will think harder about it and make fewer assumptions about its behaviour. Or perhaps just that code should be hard to maintain, since it was hard to write.

其他人喜欢用常量向后写比较,这样可以避免像<$ c $这样的错误当你的意思是 if(x == 5)时,c> if(x = 5)。任何现代编译器都会警告你这个错误,所以再次,它唯一的真正目的是让代码更难阅读。

Others like to write comparisons with constants backwards, which prevents mistakes like if (x = 5) when you meant if (x == 5). Any modern compiler will warn you about this mistake, so again its only real purpose is to make the code harder to read.

结合这两个行为给出了奇怪的代码。

Combining these two behaviours gives the bizarre code you posted.

这是一种风格。我不是风格的判断,但如果你喜欢保持程序员的脚趾,这当然是这样。

It's a style. I'm no judge of style, but if you like to keep maintainence programmers on their toes, it certainly does that. Personally, I like my code to be readable, but that's just me.

我曾遇到过返回&& !b 在大约十行代码中实现。第一行是 switch(a)

I once encountered return a && !b implemented in about ten lines of code. The first line was switch(a).

这篇关于if(false == condition)。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 03:19