用!或者= = false?你的偏好? [英] using ! or == false? your preference?

查看:63
本文介绍了用!或者= = false?你的偏好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好!


在巴塞罗那Tech-ED的中间会议期间,我无意中听到了一些开发人员之间的讨论。讨论的主题是代码

布局(即每个开发人员如何格式化和编写代码)。你的

有以下两个例子吗?您会选择哪一个以及为什么?


//对于简短的陈述可能更容易阅读

if(boolean == false){}

if(DetermineResultFromMethod(arg1,arg2)== false)){}





//更容易更长时间声明?

if(!boolean){}

if(!DetermineResultFromMethod(arg1,arg2)){}


Thinking关于它,我们已在办公室多次进行过这次讨论,

我从未见过有关此主题的公开讨论。


-

关于

Anders Borum / SphereWorks

微软认证专家(.NET MCP)

解决方案



个人偏好,我总是选择== false如果只有一个原因......我的眼睛有时会错过一个单词!

Anders Borum < an **** @ sphereworks.dkwrote in message

news:%2 ***************** @ TK2MSFTNGP04.phx.gbl .. 。


你好!


在巴塞罗那Tech-ED的中间会议期间,我无意中听到了>
一些开发人员之间的讨论。讨论的主题是代码

布局(即每个开发人员如何格式化和编写代码)。你的

有以下两个例子吗?您会选择哪一个以及为什么?


//对于简短的陈述可能更容易阅读

if(boolean == false){}

if(DetermineResultFromMethod(arg1,arg2)== false)){}





//更容易更长时间声明?

if(!boolean){}

if(!DetermineResultFromMethod(arg1,arg2)){}


Thinking关于它,我们已在办公室多次进行过这次讨论,

我从未见过有关此主题的公开讨论。


-

关于

Anders Borum / SphereWorks

微软认证专家(.NET MCP)



Dan Bass schrieb:


个人偏好,我总是选择== false如果只有一个原因......我的眼睛有时会错过一个单独的!。



所以我有其他个人偏好。


如果代码不是更难理解,我更喜欢更短的代码。


和一个!而不是== false而不是更短但不难更难理解(假设你没有视力不好或眼镜不好)

问候,


Martin


definatley第一个。它更容易阅读。


-

如果无知是幸福,那就擦掉我脸上的笑容。

" Anders Borum"写道:


您好!


在巴塞罗那Tech-ED的中间会议期间,我无意中听到了/>
一些开发人员之间的讨论。讨论的主题是代码

布局(即每个开发人员如何格式化和编写代码)。你的

有以下两个例子吗?您会选择哪一个以及为什么?


//对于简短的陈述可能更容易阅读

if(boolean == false){}

if(DetermineResultFromMethod(arg1,arg2)== false)){}





//更容易更长时间声明?

if(!boolean){}

if(!DetermineResultFromMethod(arg1,arg2)){}


Thinking关于它,我们已在办公室多次进行过这次讨论,

我从未见过有关此主题的公开讨论。


-

关于

Anders Borum / SphereWorks

微软认证专家(.NET MCP)


Hello!

While in-between sessions at the Tech-ED in Barcelona, I overheard a
discussion between some developers. The subject of the discussion was code
layout (i.e. how each developer formats and writes code). What are your
takes at the following two examples? Which one would you choose and why?

// may be easier to read for short statements
if (boolean == false) {}
if (DetermineResultFromMethod(arg1, arg2) == false)) {}

or

// easier for longer statements?
if (! boolean) {}
if (! DetermineResultFromMethod(arg1, arg2)) {}

Thinking about it, we''ve had this discussion at the office several times,
and I''ve never seen any public discussion on the subject.

--
with regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)

解决方案


Personal preference, I always go for "== false" if for one reason only... My
eye sometimes misses a single "!"
"Anders Borum" <an****@sphereworks.dkwrote in message
news:%2*****************@TK2MSFTNGP04.phx.gbl...

Hello!

While in-between sessions at the Tech-ED in Barcelona, I overheard a
discussion between some developers. The subject of the discussion was code
layout (i.e. how each developer formats and writes code). What are your
takes at the following two examples? Which one would you choose and why?

// may be easier to read for short statements
if (boolean == false) {}
if (DetermineResultFromMethod(arg1, arg2) == false)) {}

or

// easier for longer statements?
if (! boolean) {}
if (! DetermineResultFromMethod(arg1, arg2)) {}

Thinking about it, we''ve had this discussion at the office several times,
and I''ve never seen any public discussion on the subject.

--
with regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)



Dan Bass schrieb:

Personal preference, I always go for "== false" if for one reason only... My
eye sometimes misses a single "!"

So I have the other personal preference.

I prefer a shorter code if the code is not more difficult to understand.

and a "!" instead of a "== false" is much shorter but not more difficult
to understand (assumed that you do not have a poor eyesight or poor glasses)
Regards,

Martin


definatley the first one. it''s much easier to read.

--
"If ignorance is bliss, then wipe the smile from my face."
"Anders Borum" wrote:

Hello!

While in-between sessions at the Tech-ED in Barcelona, I overheard a
discussion between some developers. The subject of the discussion was code
layout (i.e. how each developer formats and writes code). What are your
takes at the following two examples? Which one would you choose and why?

// may be easier to read for short statements
if (boolean == false) {}
if (DetermineResultFromMethod(arg1, arg2) == false)) {}

or

// easier for longer statements?
if (! boolean) {}
if (! DetermineResultFromMethod(arg1, arg2)) {}

Thinking about it, we''ve had this discussion at the office several times,
and I''ve never seen any public discussion on the subject.

--
with regards
Anders Borum / SphereWorks
Microsoft Certified Professional (.NET MCP)


这篇关于用!或者= = false?你的偏好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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