Re: RFC 106 (v1) Yet another lexical variable proposal: lexical variables made default
[email protected] ("J. David Blackstone") Thu, 17 Aug 2000 18:30:09 -0500
| Newsgroups | perl.perl6.language.strict |
|---|---|
| Message-ID | <[email protected]> |
> Perl6 RFC Librarian writes: >> The chief instance where Perl5 requires dynamic variables is in the >> case of package globals. > > I think this is a bad idea (so I'm glad you made it optional). Thanks for the feedback, Nat. I figured the idea would meet with resistance. Really, since the whole RFC is optional, I guess we shouldn't have to specify part of it as "optional", but I didn't want to jeopardize acceptance of the idea by tying an extra issue to it. (A gigantic leap would be great, but a moderate gain sure beats nothing.) > Global variables are important. They provide a mechanism for a > separate module to add new behaviour to Perl: global variables > function as configuration information that can be accessed by other > packages (e.g., Exporter), and is used in the more general case of > subclasses needing access to superclasses' innards. They're an > escape hatch for programmers: language didn't build something in? > Add it on! Grafting your own stuff into another module's package > is how Class::Struct works, and I'm still unconvinced there should > be a difference between subs and data in this respect. I agree with you. However, I am unable to find a case in which a package global could not be replaced with a lexical defined in the module's .pm file and an accessor method for it. Even if you are extending a class, you can still provide this. I'm willing to listen to reason, however, if I'm nuts. :) > Any suggestion to make lexical variables accessible from outside > their scope to solve this is also extremely dangerous (IMHO). Right. If you did that, they wouldn't be lexical variables. Now, I mentioned in the radical optional section about eliminating dynamic variables that lexical variables could be made package variables, though still only accessible from within the same file or block. I'm thinking that's a bad idea, though, because it doesn't gain much. Packages were created as a means of hiding dynamic variable namespaces from each other -- this isn't needed if dynamic variables are eliminated. The only thing packages would really be needed for if such a radical course of action were taken would be the use they've been extended to cover: defining classes. (Of course, they would still be wanted for separating _functions_ into separate namespaces, but that's a separate issue from variables.) >> Very little will have to be done to translate Perl5 to Perl6 under >> this proposal. > > Except if global variables are eliminated. Depends on what you mean by very little. :) If they aren't eliminated, almost nothing will be required. If they are, you'll have to translate each package variable that is intended to be accessed from outside the file where it is defined into a lexical variable with an accessor method. Still mostly mechanical, though, I think. J. David