最近CS毕业生的圈数和合规性 [英] Loops and compitency of recent CS grads

查看:69
本文介绍了最近CS毕业生的圈数和合规性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我一直注意到的趋势而好奇。


在这里,大多数新生甚至是一些专业人士

拾取C ++或其他类似语言往往会产生低效的循环/迭代,例如:


array [0] = 0;

for(int i = 1; i< size; ++ i)

{

array [i] = i;

}


或我最喜欢的

for(int i = 0; i< 2 * size; ++ i)

{

if(i%2 == 0)

dofunct(array [i / 2]);

else

dootherfunct(array [i / 2]);

}


正确的迭代真的难以理解吗?

Just sort of curious because of a trend I''ve been noticing.

Around here, most of the newer students and even some professionals
that pick up C++ or another similar language tend to do inefficient
things with loops / iterations, such as:

array[0] = 0;
for (int i =1; i < size; ++i)
{
array[i] = i;
}

or my favorite
for (int i = 0; i < 2*size; ++i)
{
if (i % 2 == 0)
dofunct(array[i/2]);
else
dootherfunct(array[i/2]);
}

Is proper iteration really that hard of a concept to grasp?

推荐答案



这是能力 ;)


Josh Mcfarlane写道:

It''s "competency" ;)

Josh Mcfarlane wrote:
array [0] = 0;
for(int i = 1; i< size; + + i)
{
array [i] = i;
}
array[0] = 0;
for (int i =1; i < size; ++i)
{
array[i] = i;
}




我可能会在这里无能为力,但是这个

循环有什么问题?


干杯,

Andre



I may be outing myself as incompetent here, but what''s wrong with this
loop?

Cheers,
Andre


in*****@gmail.com 写道:
这是能力。 ;)

Josh Mcfarlane写道:
It''s "competency" ;)

Josh Mcfarlane wrote:
array [0] = 0;
for(int i = 1; i< size; ++ i)
{
array [i] = i;
}
array[0] = 0;
for (int i =1; i < size; ++i)
{
array[i] = i;
}



我可能会在这里无能为力,但这有什么不对br?>循环?



I may be outing myself as incompetent here, but what''s wrong with this
loop?




抱歉拼写错误。 = P


基本上,在这个例子中它可能具有误导性,但我看到代码

它们复制了初始值。


一个更好的例子可能是


array [0] + = x

for(int i = 1; i< size ; ++ i)

{

array [i] + = x;

}


或者需要在整个

迭代中执行的其他一些常见操作。对我来说,这是代码重复而且更麻烦的是

维护代码,其中初始迭代(0)在循环之外,

而剩余的迭代在里面。


Josh McFarlane



Sorry for the mispelling. =P

Basically, in this example it may have been misleading, but I see code
where they duplicate the initial value.

A better example may have been

array[0] += x
for (int i = 1; i < size; ++i)
{
array[i] += x;
}

Or some other common operation that needs to be performed on the entire
iteration. To me, it''s code duplication and more of a hassle to
maintain code where the initial iteration (0) is outside of the loop,
while the remaining iterations are inside.

Josh McFarlane


2005-10-28,在***** @ gmail.com < in ***** @ gmail.com>写道:
On 2005-10-28, in*****@gmail.com <in*****@gmail.com> wrote:

它是能力 ;)

Josh Mcfarlane写道:

It''s "competency" ;)

Josh Mcfarlane wrote:
array [0] = 0;
for(int i = 1; i< size; ++ i)
{
array [i] = i;
}
array[0] = 0;
for (int i =1; i < size; ++i)
{
array[i] = i;
}



我可能会在这里无能为力,但这有什么不对br />循环?



I may be outing myself as incompetent here, but what''s wrong with this
loop?




他可能希望它更具惯用性:


for(int i = 0; i < size; ++ i)

{

array [i] = i;

}


如果我要看原始代码,


for(int i = 1;


开头,小闹钟会开始在脑子里开始,

我不得不浪费时间证明自己没有错。


-

Neil Cerutti



He may wish it were the more idiomatic:

for (int i = 0; i < size; ++i)
{
array[i] = i;
}

If I were to see the original code, with

for (int i = 1;

at the beginning, little alarms would start going off in my head,
and I''d have to waste time proving to myself it wasn''t wrong.

--
Neil Cerutti


这篇关于最近CS毕业生的圈数和合规性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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