Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: keywords versus variables

by papidave (Monk)
on Sep 08, 2007 at 16:21 UTC ( #637847=note: print w/ replies, xml ) Need Help??


in reply to keywords versus variables

I'm afraid I have to vote with ambrus on this one, for most cases. The problem, as I see it, isn't the number of variables, but the distance between the definition of those variables and the location(s) where they are used. In addition to the OOP methods mentioned above, declaring your my variables in a short scope can go a long way towards improving readability.

The most obvious case would be the replacement of a single global variable with a scope-restricted variable and access methods for it. IMHO, this would be an improvement even if the code that uses those access methods needs additional temporary vars to work with it.

{ # scope of foo_tracker my $foo_count; sub found_a_foo() { ++$foo_count; } sub foo_count() { $foo_count; } sub killed_a_foo() { --$foo_count; } } # scope of foo_cache

That said, I do favor refactoring code to reduce the number of variables passed into a function, or the number of levels through which an argument is passed before it gets used.


Comment on Re: keywords versus variables
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-09-16 04:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (155 votes), past polls