in reply to Re: extracting corresponding values from another array
in thread extracting corresponding values from another array
Second for my $i (map {$_ * 2} 0 .. 1000000 / 2) {$sum += $i} is nothing like the while statement. Nothing. At bare minimum the while statment does not iterate over a list twice.
But then, don't say that when we change the $i += 2 to $i ++ the alternative is a foreach. That would also be closer to the while.
On an abstract level the for(;;) while()continue() and foreach ($i..$j) are identical. At a implementation level the for(;;) and while() are identical, and for($i..$j) is not. And I think few people would say that the practical alternative to for(my $i;$i<10_000;$i++) is a while() structure. Certainly any programmers familiar with the for ($i..$j) would not.
I know the foreach is more efficient than the for, but only in the case of incrementing the variant by 1.
And that was precisely my point, and you know it.
The for() is a less error-prone, and easier way of writing the while.
I dispute this statement. I do not believe it to be true AT ALL, and even less true for NON-C (like language) programmers. And frankly until you can present some studies that show that cognitively people make less errors with the for(;;) construct than they do with while() im not even going to discuss it. And for two reasons: first I never made any statements regarding these two until this very paragraph, my point was the people make less errors in the case of iterating by 1 when using foreach. Second considering that a big chunk of the programmers out there have minimal exposure to it, I am seriously in doubt as to why a perfectly clear structure analagous or equivelent to structures available in just about every imperative language would produce more errors than one that is as cryptic as for(;;).
The only part of your last statement that I agree with is that the for(;;) form is easier to write than the while() form. And for good reason. Thats precisely why it was put in the language in the first place. A trade off of legibility for ease of use in application, especially when riduculously slow connections were the norm.
--- demerphq
my friends call me, usually because I'm late....
|
|---|