一个Philisophical问题 [英] A Philisophical Question

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

问题描述

以下是实现同一目的的两种不同方式:


to_len? memmove(ptr,l_to,to_len),ptr + = to_len:NULL;





if(to_len){

memmove(ptr,l_to,to_len);

ptr + = to_len;

}


我喜欢第一个,但是鉴于不是每个人都掌握三元的b $ b和逗号运算符,第二个更有可能是有道理的。还有其他

想法吗?

解决方案

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

以下是实现同一目的的两种不同方式:

to_len ? memmove(ptr,l_to,to_len),ptr + = to_len:NULL;



if(to_len){
memmove(ptr,l_to,to_len) ;
ptr + = to_len;
}

我喜欢第一个,但鉴于不是每个人都掌握三元和逗号操作员,第二个更可能有意义。还有其他的想法吗?



是的,这里是一个:不要将语句用作表达式,这样你就可以了

简洁。


这里是另一个:而不是NULL,任何其他指针表达式将是/ b $ b。 NULL是一个随意的元素,它应该告诉你

你在做什么是不对的。


简而言之:如果是的话有条件地执行陈述,那是什么

它的存在。使用三元运算符有条件地评估

表达式,这就是那里的那个。你可以混合搭配

C并不代表你应该这样做。


这不是哲学问题,它是一个问题风格问题。


S.


文章< 11 ************ **********@g47g2000cwa.googlegroups .com> ;,

< st ***** @ yahoo.com>写道:

这是实现同一目的的两种不同方式:

to_len? memmove(ptr,l_to,to_len),ptr + = to_len:NULL;



if(to_len){
memmove(ptr,l_to,to_len) ;
ptr + = to_len;
}

我喜欢第一个,但鉴于不是每个人都掌握三元和逗号操作员,第二个更可能有意义。还有其他的想法吗?




第一个可能在宏中很有用,所以它可以在

中使用表达式,但否则价值的无意义回报会降低

的可读性,以至于超过简洁性。


如果你想做的就是保存垂直空间,然后


if(to_len){memmove(ptr,l_to,to_len); ptr + = to_len;}


比表达式更清晰,也更短。


- Richard


Richard Tobin写道:


文章< 11 ********************* *@g47g2000cwa.googlegroups .com> ;,
< st ***** @ yahoo.com>写道:

这是实现同一目的的两种不同方式:

to_len? memmove(ptr,l_to,to_len),ptr + = to_len:NULL;



if(to_len){
memmove(ptr,l_to,to_len) ;
ptr + = to_len;
}

我喜欢第一个,但鉴于并非所有人都掌握了
三元和逗号运营商第二个更有可能是有意义的。
任何其他想法?
第一个可能在宏中有用,




OK

这样它就可以用在表达式中,但是否则值的无意义返回会降低可读性,从而超过简洁性。

如果你想要的只是保存垂直空间,那么

if(to_len){memmove(ptr,l_to,to_len); ptr + = to_len;}

比表达式版本更清晰,也更短。




一旦你开始编写的程序不是适合屏幕,

显然优先应该是改善

屏幕适合的清晰度。

我不要认为有那么多努力来节省垂直空间。


-

皮特


Here are two different ways of accomplishing the same end:

to_len ? memmove(ptr, l_to, to_len), ptr += to_len : NULL;

or

if ( to_len ) {
memmove( ptr, l_to, to_len );
ptr += to_len;
}

I like the first one, but in light that not everyone grasps the ternary
and comma operators the second is more likely to make sense. Any other
ideas?

解决方案

st*****@yahoo.com wrote:

Here are two different ways of accomplishing the same end:

to_len ? memmove(ptr, l_to, to_len), ptr += to_len : NULL;

or

if ( to_len ) {
memmove( ptr, l_to, to_len );
ptr += to_len;
}

I like the first one, but in light that not everyone grasps the ternary
and comma operators the second is more likely to make sense. Any other
ideas?


Yes, here''s one: don''t use statements as expressions just so you can be
terse.

Here''s another one: instead of NULL, any other pointer expression would
do. The NULL is an arbitrary element, which should tell you that what
you''re doing isn''t right.

In short: use if for conditionally executing statements, that''s what
it''s there for. Use the ternary operator for conditionally evaluating
expressions, that''s what that''s there for. That you can mix and match in
C doesn''t mean you should.

It''s not a question of philosophy, it''s a question of style.

S.


In article <11**********************@g47g2000cwa.googlegroups .com>,
<st*****@yahoo.com> wrote:

Here are two different ways of accomplishing the same end:

to_len ? memmove(ptr, l_to, to_len), ptr += to_len : NULL;

or

if ( to_len ) {
memmove( ptr, l_to, to_len );
ptr += to_len;
}

I like the first one, but in light that not everyone grasps the ternary
and comma operators the second is more likely to make sense. Any other
ideas?



The first one might be useful in a macro, so that it could be used in
an expression, but otherwise the meaningless return of a value reduces
the readability so much as to outweigh the terseness.

If all you want to do is save vertical space, then

if(to_len) {memmove(ptr, l_to, to_len); ptr += to_len;}

is clearer than the expression version and also shorter.

-- Richard


Richard Tobin wrote:


In article <11**********************@g47g2000cwa.googlegroups .com>,
<st*****@yahoo.com> wrote:

Here are two different ways of accomplishing the same end:

to_len ? memmove(ptr, l_to, to_len), ptr += to_len : NULL;

or

if ( to_len ) {
memmove( ptr, l_to, to_len );
ptr += to_len;
}

I like the first one, but in light that not everyone grasps the
ternary
and comma operators the second is more likely to make sense.
Any other ideas?
The first one might be useful in a macro,



OK
so that it could be used in
an expression, but otherwise the meaningless return of a value reduces
the readability so much as to outweigh the terseness.

If all you want to do is save vertical space, then

if(to_len) {memmove(ptr, l_to, to_len); ptr += to_len;}

is clearer than the expression version and also shorter.



Once you start writing programs that don''t fit on a screen,
it becomes obvious that the priority should be on improving
the clarity of what does fit on the screen.
I don''t think there''s much point in trying that hard
to save vertical space.

--
pete


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

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