Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: How to write better code?

by imp (Priest)
on Dec 04, 2006 at 17:20 UTC ( #587704=note: print w/ replies, xml ) Need Help??


in reply to Re^2: How to write better code?
in thread How to write better code?

Your implementation using map instead of foreach is slightly more readable, but will be more cumbersome to maintain and debug if additional parsing is required. It is likely a short-term win that will result in a comment block that is larger than the code after a few upgrades are made.

Another weakness of using map for this is that CGI allows a parameter to have multiple values, but the code you provided will only use the last value.


Comment on Re^3: How to write better code?
Re^4: How to write better code?
by johngg (Abbot) on Dec 04, 2006 at 20:21 UTC
    If the task becomes more complex then I would almost certainly rewrite the code with more explicit control structures and descriptive variable names rather than jump through hoops making the map fit. I am only throwing away one line, when all's said and done.

    I agree with your comment about CGI and said as much at the top of my post, which was more a comment on the code snippet itself and it's legibility rather than it's suitability for parsing CGI.

    Cheers,

    JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://587704]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-09-21 07:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (167 votes), past polls