Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
But your choice is unfortunate.

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.

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,$/}"
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.

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....


In reply to Re: Re: Re: What training do YOU need? by demerphq
in thread What training do YOU need? by deprecated

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-29 09:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found