如果(表达)检查 [英] if (expression) check

查看:64
本文介绍了如果(表达)检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

检查if(表达式)与if(表达式)之间的区别是什么?在A

和B?我习惯了风格A,如果(0 == a),但是我的同行评审员

喜欢风格B,我怎样才能保护自己保持风格A?


风格A:

....

....

int a = 1 ;

if(0 == a)

{

/ *不要写我的名字* /

}

....

....


风格B:

....

....

int a = 1;

if(a == 0)

{

/ *不要写我的名字* /

}

....

....

解决方案

ja ************ @ yahoo.com 写道:

检查if(表达式)之间有什么区别)"在A
和B?我习惯了风格A,如果(0 == a),但是我的同行评审员喜欢风格B,我怎样才能保护自己保持风格A?




就个人而言,我更喜欢if(a == 0)。风格 - 虽然我知道有些人

喜欢if(0 == a)风格,因为它减少了编译时滑动的错误(而非比较)错误的机会。

我会向你的同行评审员解释这个理由。


话虽如此,只要你保持稳定,恕我直言就可以了。

清楚;在不了解您的情况的情况下,很难说您的

审稿人是否有权不同意:-)


Steve

-

Stephen Hildrey

邮件: st *** @ uptime。 org.uk /电话:+442071931337

Jabber: st***@jabber.earth。 li / MSN: fo*@hotmail.co.uk


< blockquote>

ja ************ @ yahoo.com 写道:

检查if(表达式)和if(表达式)之间的区别是什么?在A
和B?我习惯了风格A,如果(0 == a),但是我的同行评审员喜欢风格B,我怎样才能保护自己保持风格A?
<风格A:
if(0 == a)

风格B:
if(a == 0)



没有BIG区别。喜欢A的人说

它可以防止写'=''而不是'==''。那些喜欢B的人b / b $ B $说这个错误可以用不那么难看的方式来防范。我是一个B人,我自己,但不要认为这是一个BIG。交易。


至于为自己辩护:观看Miss Congeniality

并在主角演示时密切关注

什么" SING"意味着。


-
Er ****** ***@sun.com


ja ************ @ yahoo.com 写道:

检查if(表达式)之间有什么区别)"在A
和B?我习惯了风格A,如果(0 == a),但是我的同行评审员喜欢风格B,我怎样才能保护自己保持风格A?

< example snipped down to the essence:>风格 - 答:
....
如果(0 == a)

风格B:
....
if(a == 0)




一个真正的优势样式A是一个被遗忘的第二个=

导致编译时错误:0 = a不编译,而a = 0

确实。

在存在编辑器和工具(如夹板)的情况下,可以向你发出类似这样的信息,这就是优势。往往是不必要的b $ b。你可以在comp.lang.c的档案中找到任意数量的论据,这两个论点在两者中是更好的。大多数人

反对它认为这是一种不太自然

的写作方式。


就个人而言,我更喜欢风格B,但如果编码

指南,项目惯例或类似的优先选择或

规定A.


如果没有这样的约定或标准,这就是

,每个人都应该被允许按照自己的喜好去做 -

其他一切主要是在我眼中欺负。

干杯

Michael

-

E-邮件:我的是/ at / gmx / dot / de地址。


What is the BIG difference between checking the "if(expression)" in A
and B ? I''m used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?

style A:
....
....
int a = 1;
if(0==a)
{
/* Don''t write my name */
}
....
....

style B:
....
....
int a = 1;
if(a==0)
{
/* Don''t write my name */
}
....
....

解决方案

ja************@yahoo.com wrote:

What is the BIG difference between checking the "if(expression)" in A
and B ? I''m used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?



Personally, I prefer the "if (a == 0)" style - though I know some people
do like the "if (0 == a)" style because it reduces the chances of
assignment (rather than comparison) errors slipping through compilation.
I would explain that rationale to your peer reviewer.

Having said that, IMHO either is fine as long as you are consistent and
clear; without knowing your circumstances, it''s hard to say whether your
reviewer has the right to disagree :-)

Steve
--
Stephen Hildrey
Mail: st***@uptime.org.uk / Tel: +442071931337
Jabber: st***@jabber.earth.li / MSN: fo*@hotmail.co.uk




ja************@yahoo.com wrote:

What is the BIG difference between checking the "if(expression)" in A
and B ? I''m used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?

style A:
if(0==a)

style B:
if(a==0)



There is no "BIG" difference. People who like A say
it''s protection against writing `='' instead of `==''. People
who like B say the mistake can be guarded against in ways
that are less ugly. I''m a B guy, myself, but don''t consider
it a "BIG" deal.

As for defending yourself: Watch "Miss Congeniality"
and pay close attention when the protagonist demonstrates
what "SING" means.

--
Er*********@sun.com


ja************@yahoo.com wrote:

What is the BIG difference between checking the "if(expression)" in A
and B ? I''m used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A ?
<example snipped down to the essence:> style A:
....
if(0==a)

style B:
....
if(a==0)



The one "real advantage" of style A is that a forgotten second =
leads to a compile time error: 0=a does not compile, whereas a=0
does.
In the presence of compilers and tools like splint that can
warn you about stuff like this, this "advantage" is often
unnecessary. You can find any number of arguments about which
of the two is better in the archives of comp.lang.c. Most people
arguing against it are of the opinion that it is a "less natural"
way of writing the condition.

Personally, I like style B better but put up with A if coding
guidelines, conventions for a project, or similar prefer or
prescribe A.

In the absence of such conventions or standards, this is something
where everyone should be allowed to do as he or she likes --
everything else is mainly bullying of some sort in my eyes.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


这篇关于如果(表达)检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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