"Josh Mcfarlane" <> wrote in message
news: oups.com...
> 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;
> }
A few ways this could come about. Some new programmer trying to think how
to do something to a variable. "lets see. I want to initialize it to 0.
That would be X = 0. Oh, X is an array, so I need X[0] = 0. There got it.
Oh, gotta do the rest. lets see, already did 0 so..."
Or, most likely. "Ahh, let me initialize my size variable array. for (int
i = 1; i < size; ++i)" later "Dang, what bug, oh, forgot to initialize 0.
Umm.. I'll just throw it up top."
>
> 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?
>
Actually, for people new to programming iteration is a total mystery. They
still have a hard time understanding how X = X + 1 can be true when their
algebra teacher told them both sides need to be equal...
Just unlearning a lot of things and learning back over.
I remember going through this phase many many years ago. When I didn't even
understand 2/3 of what I wrote, but it worked dag nab it so it must be
right! I better not touch it or I might break it again...
|