in reply to use fields, underscores and subclasses

So, how do I create variables that are visible to subclasses but tell the user not to use them if they know what's good for them?
Well, first of all, (IMO), it's never a good idea to access attributes from other classes (or objects) directly. So the user doesn't need to be told that it's a bad idea for a specific class - it's always a bad idea.

Second, if you want to tell the user something, use POD.

If perl doesn't have a concept of protected variables, then class inheritance becomes pointless, surely.
Well, Perl doesn't even have the concept of object instance variables. Can't really blame Perl not to have a specific flavour of a thing it doesn't have to begin with. Perl's OO is the opposite of the rest of Perl. Most of Perl is about programmer convenience, letting the programmer focus on the important things, and having the language take care of the details. But when it comes to OO, Perl gives the programmer only two things: @ISA and bless. And that's it. Everything else you have to do yourself.
  • Comment on Re: use fields, underscores and subclasses

Replies are listed 'Best First'.
Re^2: use fields, underscores and subclasses
by MattLG (Beadle) on Nov 23, 2008 at 02:01 UTC

    > it's never a good idea to access attributes from other classes (or objects) directly. So the user doesn't need to be told that it's a bad idea for a specific class - it's always a bad idea.

    So, are you saying the whole convention of underscoring "private" variables is pointless?

      So, are you saying the whole convention of underscoring "private" variables is pointless?
      IMO, yes. I've never written code where setting an attribute in another object or class was part of the API. I'd prefer if the language didn't even allow access to attributes that aren't both of the same class and the same object.
Re^2: use fields, underscores and subclasses
by LanX (Saint) on Nov 23, 2008 at 01:09 UTC
    > Perl gives the programmer only two things: @ISA and bless.

    you forgot -> for blessed refs! 8 )

    Cheers Rolf

      no he didn't, -> is for REFs, and @ISA/bless is for OO

        -> in general is for refs, but ->name is for OOP. It even works on more than refs.

        JavaFan also forgot the universal base class UNIVERSAL and the methods is provides.

        nope!

        -> has a special meaning for OOP to call with an included extra parameter ... the packagename or the selfref.

        just try ->name on a unblessed ref ...

        ...and log in again ;)

        perlop

        Otherwise, the right side is a method name or a simple scalar variable containing either the method name or a subroutine reference, and the left side must be either an object (a blessed reference) or a class name (that is, a package name).

        Cheers Rolf