in reply to Re: Re: What training do YOU need?
in thread What training do YOU need?
Interesting comment. Id be interested in hearing more about why you think this was an unfortunate choice.
And how the C-style loop is more cumbersome but more adaptable.
A C-Style for loop is always functionally and internally equivelent to a suitably constructed while loop. The primary differences being that many programmers from a C tradition find the for(;;) syntax more readable, while the rest of us find the while syntax more readble and maintainable. I am in the latter group. :-) Nine time out of ten (more really) when I see someone use a C-Style for loop they are not exploiting the equivelence to a while , but rather using a slightly less readble, more error prone and less efficient form of a for (LIST) loop. I avoid the term foreach because foreach is a synonym to for in perl, they are identical.
Insofar that the majority of its use is to simulate for ($m..$n) where $m<$n I think advising people to convert to the more legible and less error prone form is probably a good idea. And I also think that its a good idea to use while () {} continue {} instead of for(;;) if only because it tends to be easier to read. Having said that in the time ive been using perl I think ive needed the construct a mere handful of times.E:\Smoke\source>perl -e "foreach (my $i=0;$i<10;$i++) { print $i,$/}" E:\Smoke\source>perl -e "for (my $i=0;$i<10;$i++) { print $i,$/}"
Ultimately id argue that for(;;) is a construct mostly provided to reduce the pain for C junkies, and that in the long term better constructs that are more intuitive and less error prone are available and so should be encouraged.
--- demerphq
my friends call me, usually because I'm late....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: What training do YOU need?
by Aristotle (Chancellor) on Oct 22, 2002 at 13:30 UTC | |
by demerphq (Chancellor) on Oct 22, 2002 at 13:47 UTC | |
by Aristotle (Chancellor) on Oct 22, 2002 at 15:30 UTC | |
|
( Re:)+ What training do YOU need?
by rir (Vicar) on Oct 22, 2002 at 14:57 UTC |