层叠ifs - 风格的问题 [英] cascading ifs--style question

查看:102
本文介绍了层叠ifs - 风格的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近有很多关于编码的讨论,以便调试器

在每一行停止,这是另一回事。在那次辩论中,

我躲在那些喜欢编写代码的人的阵营中,

每个陈述都在一个单独的行上(虽然我不能
停止使用:?)。我很想得到以下的意见

风格:


而不是:

if(a&& b) )

foo();


使用:

if(a)

if(b )

foo();


这种风格将条件放在不同的行上,所以它b / b
对它有利。但我认为它很少有其他的兑换功能,而且有点难看。


你的想法?

Lots of discussion lately on coding so that the debugger
stops on each line, and this is yet another. In that debate,
I fall in the camp of those who like code written such that
every statement is on a separate line (although I can''t
stop using :?). I am curious to get opinions on the following
style:

instead of:
if( a && b )
foo();

use:
if( a )
if( b )
foo();

This style puts the conditionals on separate lines, so it
has that in its favor. But me thinks it has very few other
redeeming features and is a bit ugly.

Your thoughts?

推荐答案

11月15日晚上8:26,William Pursell< bill.purs ... @ gmail.comwrote:
On Nov 15, 8:26 pm, William Pursell <bill.purs...@gmail.comwrote:

最近有很多关于编码的讨论,以便调试器

在每一行停止,这是另一回事。在那次辩论中,

我躲在那些喜欢编写代码的人的阵营中,

每个陈述都在一个单独的行上(虽然我不能
停止使用:?)。我很想得到以下的意见

风格:


而不是:

if(a&& b) )

foo();


使用:

if(a)

if(b )

foo();


这种风格将条件放在不同的行上,所以它b / b
对它有利。但是我觉得它很少有其他的兑换功能,而且有点难看。


你的想法?
Lots of discussion lately on coding so that the debugger
stops on each line, and this is yet another. In that debate,
I fall in the camp of those who like code written such that
every statement is on a separate line (although I can''t
stop using :?). I am curious to get opinions on the following
style:

instead of:
if( a && b )
foo();

use:
if( a )
if( b )
foo();

This style puts the conditionals on separate lines, so it
has that in its favor. But me thinks it has very few other
redeeming features and is a bit ugly.

Your thoughts?



我认为编码是一个错误,以便调试器很高兴。


按照的方式编写最清楚的。如果您的眼睛中的替代品绝对相等,那么选择您喜欢的那个(包括使调试器满意的那个
)。

I think it is a mistake to code so that the debugger is happy.

Write it the way that is the most clear. If alternatives are
absolutely equal in your eyes, then choose the one you like (including
the one that makes the debugger happy).


William Pursell写道,On 16/11/07 04:26:
William Pursell wrote, On 16/11/07 04:26:

最近有很多关于编码的讨论,以便调试器

在每一行停止,这是另一个。在那次辩论中,

我躲在那些喜欢编写代码的人的阵营中,

每个陈述都在一个单独的行上(虽然我不能
停止使用:?)。我很想得到以下的意见

风格:


而不是:

if(a&& b) )

foo();


使用:

if(a)

if(b )

foo();


这种风格将条件放在不同的行上,所以它b / b
对它有利。但是我觉得它很少有其他的兑换功能,而且有点难看。


你的想法?
Lots of discussion lately on coding so that the debugger
stops on each line, and this is yet another. In that debate,
I fall in the camp of those who like code written such that
every statement is on a separate line (although I can''t
stop using :?). I am curious to get opinions on the following
style:

instead of:
if( a && b )
foo();

use:
if( a )
if( b )
foo();

This style puts the conditionals on separate lines, so it
has that in its favor. But me thinks it has very few other
redeeming features and is a bit ugly.

Your thoughts?



首先,我相信使代码调试器变得友好,但只有这样才能使它对人类不友好。


我同意这很难看。如果不是函数调用你可以很容易地检查所有变量和子表达式的条件,这样你就可以看看为什么它已经采取或未采取分支。如果b是一个函数调用

,那么将会有更多的论据将其分离出来,但不是

必然是决定性的。


考虑到这一切,我会使用第一个表格。

-

Flash Gordon

Firstly, I believe in making the code debugger friendly, but only where
it does not make it human unfriendly.

I agree that it is ugly. If it is not function calls you can easily
check the condition of all the variables and sub-expression so you can
see why it has taken or not taken the branch. If b was a function call
there would be more of an argument for separating it out, but not
necessarily conclusive.

Considering all that, I would use the first form.
--
Flash Gordon


Ugly。


while(x&& y);


将成为


if(x )

while(y)

if(!x)

break;
Ugly.

while(x && y);

would become

if(x)
while(y)
if(!x)
break;


这篇关于层叠ifs - 风格的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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