Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: keywords versus variables

by papidave (Pilgrim)
on Sep 08, 2007 at 16:21 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-19 05:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found