|There's more than one way to do things|
Re: Default Scope Behaviourby dchetlin (Friar)
|on Jan 01, 2001 at 06:54 UTC||Need Help??|
While Dominus is in part right that the discussion on
perl6-language-strict could have been more productive, there
are indeed issues that make this less than easy to do.
I'm working on a paper for this, so I don't want to give everything away early, but the basic upshot is that there are three languages often mentioned in the same breath as Perl that do make variables lexical by default, each in different ways. And, as you might imagine, each of them has their own problems.
Python has only two real scopes -- global and nearest-enclosing-block lexical. If Perl went this way, we would lose a *lot* of flexibility.
Ruby does a better job with scopes, but it is very easy to create action-at-a-distance problems. I.e. you write a function that has a tightly enclosed lexical scope. A year later, you add a variable 300 lines above it that happens to have the same name as a variable in that tight lexical scope, and all of the sudden the two variables are the same -- you've inadvertently changed the scope of a lexical.
Tcl gives the most flexibility of the three, but you end up with all kinds of `upvar' nonsense to try and place variables in the scopes you want them. Easy to screw up and also very verbose.
In sum, there are possibly better ways to do it than the way Perl does it now, but figuring out the semantics that are best is far from easy.
I hope to finish my paper sometime soon, and if people are interested I'll post it here for comments before I make it public. It will hopefully be able to suggest a reasonable semantic for Perl 6.