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

Re: Why is 'our' good?

by TimToady (Parson)
on Sep 24, 2004 at 21:16 UTC ( #393672=note: print w/ replies, xml ) Need Help??


in reply to Why is 'our' good?

Something that seems to be missed every time this discussion is referenced is that the main purpose of our is not to replace use vars, but to serve as a syntactic peg upon which lexically scoped traits can be hung. The purpose of our is to provide a lexically scoped view of a global variable. The variable itself might not be constant, for instance, but I might want to declare it that way for the sake of my own discipline. Beyond that, various forms of allomorphism will only get more important as Perl 6 allows more type and trait declarations within variable and subroutine declarations. But even leaving allomorphism out of it, traits are becoming much more important in Perl 6. For instance, exported variables in Perl 6 are simply marked with an "is export" trait rather having to duplicate their names in an @EXPORT_OK list somewhere.

The secondary reason for having a lexically scoped declaration is to limit your exposure to accidental use of the variable. But really, that's just another aspect of controlling the "view", or non-view, in this case.

I doubt we'll all ever see eye-to-eye on the subject of globals, but at least grant me the privilege of pointing out that, at least in my mind, the feature was added more to future-proof the declaration syntax than out of reaction to use vars. I freely admit that our is of marginal benefit in Perl 5, but I was already thinking ahead to Perl 6 at that point, even if Perl 6 hadn't been named yet. :-)


Comment on Re: Why is 'our' good?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2014-07-13 00:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (242 votes), past polls