Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
I don't know what's so bad about a "C-style for loop"

There are two problems with C style for loops. First they are prone to fencepost errors. In fact programmers that dont have a C/Java background get them wrong an awful lot, for instance I come from a Pascal background, and despite being a reasonably good programmer often make mistakes when I use them. (hence I dont use them if I can get away with it).

Second is that they are marginally less efficient than perl style for loops. Granted this isnt the best argument, but combined with the former its IMO pretty good reasoning that avoiding them is a good way to reduce error, speed up your code and leave a more maintainable product (the later is excellent justifiction IMO).

it isn't there so people can complain about its usage

No its there to make C programmers feel more at home. Presumably a C programmer has already learned the subtleties of this style of loop and so will not make the common errors as often. This doesnt mean that it should be recommended or even overlooked, especially as the alternative is so much superior.

As for your solution ++. splice() is one of those tools that I have yet to become entirely comfortable with. I suppose its something I should try to use more often.

Good post, thanks.

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.


In reply to Re: Re: using two arrays to make a table by demerphq
in thread using two arrays to make a table by Bongo

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 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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2021-07-30 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?