Perl's OO encapsulation is weak at best
There can be levels of encapsulation. And this may not be a good thing. Acording to
Stroustrup in C++ there is one too many. In
The design and evolution of C++ page 302 he says
In retrospect, I think that protect
is a case where "good arguments" and fashion
overcame my better judgement and my rules of thumb for accepting new features.
Admittedly in Perl there is no level of encapsulation.
Object variable members are accessible to anyone but
people cannot access one by mistake unlike C++ because
in Perl one must explicitly mention the object when
accessible a member variable $self->{var}.
Perl6 will probably be hoepfully less verbose while still avoiding the
C++ potnetial ambiguity: $.var (note the dot that means
that a member variable is accessed). In C++, in a member
method, you can access by mistake a member variable
of the class or a parent class when you thought you were
accessing a global variable or if you forgot to declare
the lexical variable you use.
Also there is two kinds of encapsulation: forced or not.
In perl no one is ever forced to anything. As I said before, there is encapsulation
in the sense that no one can unwillingly access object
data.
BTW: C++ forced encapsulation is a joke because it is so easy to defeat. It is just a compilation thing, no check at link time:
#define private public
#define protected public
#define class struct
Anyway, one must always be careful of language comparaison
because one always uses the metric adapted for its favorite
language. Judging a language only for its OO-ness is a very
restricted view in my opinion.
In fact pure OO language are insanely verbose for the
"Hello World" test. One of the perl feat is to scale
from oneliners to moderately big programs. In this case,
good score in the "pure OO-ness" metric is a _bad_ thing.
Corrected the Stroustrup reference
--
stefp -- check out TeXmacs
wiki |