Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Basic programming question

by tall_man (Parson)
on Jan 27, 2005 at 16:31 UTC ( [id://425606]=note: print w/replies, xml ) Need Help??


in reply to Basic programming question

There are several reasons to prefer B to A, IMHOP.

1) It is good practice to apply the principle of initializing variables to valid values as soon as they are declared.

2) The second way is more efficient. You avoid generating the code for entering an extra scope level (the else).

3) You may think the first way is avoiding an assignment to $T but that is not the case. Code is generated to assign an undef to it. (Update: I think I was mistaken about this one.. But the extra assignment cost is neglibible.)

4) It is just as readable, if not more so. You can view "AM" and an unmodified hour as the default, and "PM" with a subtracted hour as the exception.

Try running both these codes with "perl -MO=Terse" and you will see the differences.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found