Tassilo v. Parseval said:
Also sprach Veli-Pekka Tätilä:
Yes, inside-out indeed seems to be Perl-centric. On the other hand, it's
nothing that would have been invented by the Perl folks. They are a
variation on the flyweight-pattern where an object is a very lightweight
entity ($dummy in the above article) and it is used to look up the real
data from some static container outside the caller's scope.
Besides avoiding typos, they have some other advantages. One is that
subclassing becomes easier and safer as the access to an object's
innards happens exlusively through accessor methods.
As a consequence, inside-out objects don't suffer from the type-dependency
other perl objects show. A standard hash class can only inherit easily
from another hash class, and only another hash class can easily inherit
from it. In contrast, any type of class can inherit from any number of
inside-out classes, and an inside-out class can inherit from one
foreign (non-inside-out) class. Multiple inheritance *from* foreign
classes involves the usual trickery, often basing inheritance on a
has-a relation.
The other big advantage of inside-out classes is that different classes
have separate lexical name spaces for their fields (properties, attributes,
object variables, whatever). Typo-safety is only a small side-aspect
of this. The main advantage is that classes don't have to co-ordinate
their internal field names (a fundamental breach of privacy), as is the
case with standard hash classes.
The reason why inside-out classes are such a big deal in Perl is that
other OO languages don't have different types of object (scalar, array,
hash, etc.) but implement only one. Also, name space separation is
usually built into a typical OO language and doesn't have to be
implemented by the user. So this particular type of light-weight
object doesn't have general advantages over other objects the way
it does in Perl.
If I had my way, I'd call what is known as inside-out classes simply
"free classes". Inside-out, besides being a mouthful, describes the
implementation in contrast to the standard implementation of hash
classes, which it has set out to make obsolete. That's bad politics.
Mathematicians call a group "free" when it has generators that are
independent of each other, without troublesome algebraic relations.
Similarly, inside-out classes are free from troublesome interrelations
of name spaces and object types.
Having free classes would make Perl the only language that has free
modules (another related mathematical term). But, as we say in
German, "Der Zug ist abgefahren" (That train is long gone).
Anno