Am 30.09.2010 10:32, schrieb Carl Mäsak:
Moritz in the spec (>>), Damian (>):
After lengthy IRC discussion, we concluded that it's a good idea to provide
some form of introspection that doesn't bother about perceived privacy
borders, provided that the implementation makes it feasible.

Wow, that's the first time I've ever been sorry not to be on IRC!

Talk about snatching (directly accessible) defeat from the jaws of
(encapsulated) victory. :-(

For what it's worth, we had exactly this discussion a couple of days
ago on IRC. I represented your views above, Damian.


To summarize, I consider myself having lost that debate. I even
demonstrate the complete unviability of my views (that privacy has any
kind of footing in Perl 6) with the below one-liner.

<masak>  rakudo: class X { has $!foo; has $!bar; has $!baz }; say
eval( foo =>  1, bar =>  2, baz =>  3).perl.subst("", "\{
").subst(/\)$/, " }")).perl
<p6eval>  rakudo 8156be: OUTPUT«{"foo" =>  1, "bar" =>  2, "baz" =>  3}␤»

As long as C<.perl>  works the way it does, there can be no real
privacy. And thus C<.get_value>  and C<.set_value>  are just convenient
access points for the same behaviour.

To re-iterate, Perl 6 has no "real" privacy by default -- both the default .new and .perl methods give you access to private attributes, unless you explicitly override them.

Could we at least specify that .get_value() and .set_value() can only
be called if the calling scope declares a C<use MONKEY_TYPING;>
so that violations of good OO practice are explicitly marked in a
consistent and easily searched-for manner?

I'm still undecided on whether or not I think C<use MONKEY_TYPING;>  is
the right way to enable this kind of privacy breakage. Maybe nothing
is needed, since the C<^>  in C<$obj.^attributes>  (or the C<HOW>)
already says "warning! meta!".

The same goes for SomeClass.^add_method and the likes; we should make a general decision whether to allow metaclass access without MONKEY_TYPING, or maybe just restrict some form of metaclass accesses to MONKEY_TYPED scopes.

I would be fine with changing get_value and set_value method names to all uppercase, as an additional warning sign, if that would comfort you in some way.


Reply via email to