http://www.perlmonks.org?node_id=332796


in reply to Private method variations

You should probably be aware that the MY:: package name will be reserved in Perl 6 for getting at your current lexical scope.

On the other hand, your approach isn't so very different from that which Perl 6 will take--private methods and attributes will essentially be off in their own chunk of namespace. Of course, Perl 6 won't need to use source filtering for that...

Anyway, you're on the right track. Now if I could convince you to use My instead of MY, your scripts will be slightly easier to translate to Perl 6.

Replies are listed 'Best First'.
Re^2: Private method variations
by adrianh (Chancellor) on Mar 01, 2004 at 14:20 UTC
    Now if I could convince you to use My instead of MY, your scripts will be slightly easier to translate to Perl 6.

    Actually, how about OUR:: instead of My:: - or is that somewhere in Perl 6 too?

    Reasoning:

    • Keeps the upper case convention of SUPER and NEXT
    • Still nice and short to type
    • Still the same sort of English meaning (this method is ours and cannot be used by other classes)
    • Functionality is closer to our than my in Perl. We're messing with the (apparent) scoping of a package variable, not a lexical.

    Sound vaguely sane?

      Actually, how about OUR:: instead of My:: - or is that somewhere in Perl 6 too?
      Well, I actually thought about that one, but didn't think you'd go for something even longer. :-)

      As for whether it's in Perl 6, the only answer I can give is: "not yet". But by and large all-uppercase names are kinda sorta reserved for Perl to grow into. More or less. So maybe Our:: would be a better choice.

        Well, I actually thought about that one, but didn't think you'd go for something even longer. :-)

        One extra character I can probably cope with :-)

        As for whether it's in Perl 6, the only answer I can give is: "not yet". But by and large all-uppercase names are kinda sorta reserved for Perl to grow into. More or less. So maybe Our:: would be a better choice.

        Your right that from an upward compatibility point of view Our:: (or My::) is clearly a better choice.

        The downside is that it then looks so much like a normal fully qualified method call. Thanks to NEXT and SUPER using UPPERCASE provides a handy cue to the developer that some magic is happening.

        Hmmm... Swings or roundabouts. Roundabouts or swings.

        Oooohhh! Just had a sneaky idea.

        "_" seems to be a valid package name. Is:

        sub _::secret { ... }; $self->_::secret();

        to evil? Even shorter that MY::, doesn't look like a "normal" fully qualified method call and we get the whole "_" thang that people are already used to.

      Maybe I am being niave but, is there something wrong with MyClass::PRIVATE:: ? It would be the least ambiguous of all IMO. I mean it would be hard to grab the PRIVATE:: root namespace, but if you are using a source filter anyway, you could generate the MyClass::PRIVATE:: "inner"-package with ease.

      -stvn
        Maybe I am being niave but, is there something wrong with MyClass::PRIVATE

        Nothing beyond the extra 4 (for OUR::) or 5 (for MY::) characters that you have to type every time you call the method :-)

        I fear I am too lazy to want to type those extra characters that often.

        It also differs a little from the meaning of "private" in some other languages since you can easily get at the method from other classes if you ask for it explicitly - it's just in another package after all.

Re^2: Private method variations
by adrianh (Chancellor) on Mar 01, 2004 at 08:22 UTC
    You should probably be aware that the MY:: package name will be reserved in Perl 6 for getting at your current lexical scope.

    Bah. And I knew that too.

    Now if I could convince you to use My instead of MY, your scripts will be slightly easier to translate to Perl 6.

    Colour me convinced :-)