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

Re: Confusion in naming variables in subroutines

by rkrieger (Friar)
on Jan 24, 2007 at 01:18 UTC ( #596180=note: print w/ replies, xml ) Need Help??


in reply to Confusion in naming variables in subroutines

As a general advice, pick variable names that clearly and specifically describe what they contain. In the long run (e.g. when you need to look at the code again in several months), that will keep things easier for you.

For a sub in which you calculate volumes and/or areas and the like, you can probably suffice with more 'generic' names such as $length, $width, $height, etc.
In your main program, you're more likely to deal with various lengths, heights, etc. For those, I would recommend naming them (for example) $box_width, $box_length, etc. if they're describing a box.

As you mentioned, little prevents you from scoping the variables and naming them similarly. Do as you prefer, of course, but from a maintainability perspective I recommend you make things stand out (i.e. use different names).

--
If you don't know where you're going, any road will get you there.


Comment on Re: Confusion in naming variables in subroutines

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2014-09-20 04:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (152 votes), past polls