Darren Duncan wrote:
> Carl Mäsak wrote:
>> 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(X.new( foo => 1, bar => 2, baz => 3).perl.subst("X.new(", "\{
>> ").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.
> 
> I think then that .perl needs to be updated so it is more expressly limited 
> and 
> only works on some objects rather than on all of them.
> 
> The way I see it, .perl is mainly about representing *value* objects in a 
> serialized form, and what it should produce is a value expression whose 
> execution results in an object which would eqv the original.

Are you using "value object" in the same sense as in the Perl 6
specification?

> Objects that you can't do that with don't make sense to be serialized and so 
> .perl can reasonably refuse to work on them.

method perl {
    die "Can't serialize objects of type $?CLASS, because ...";
}

> I don't think anyone can argue that every object of every class can 
> reasonably 
> be serialized with .perl and so it should only try where it makes sense.  Now 
> if 
> .perl is also savvy enough to take a reference to a subroutine and can 
> produce 
> the source code for said subroutine, I'd have a bit less of a case.

I don't understand the connection; How would you serialize an open socket?

> Bottom line, if .perl isn't supposed to work on 100% of objects then we 
> should 
> fix .perl so it doesn't break encapsulation.

+1. The question is: how?

My proposal: the default .perl method should only spit out value for
public attributes, ie those that have accessors. Maybe .new should also
default to his behavior.

> Or maybe so that we can have our cake and eat it too, there should be two 
> .perl 
> where the first is more restricted like I say and the second just dumps the 
> private attributes, and the second can only be used with MONKEY PATCHING.

1) please don't abuse MONKEY_TYPING for anything that might look like
dangerous
2) I find .perl very, very valuable in real world debugging; I don't
want to make it its usage any harder.

> Then Damian's position (which I support) is supported and so are monkeys.

Ook ook!
Moritz
(who actually writes Perl 6 code on a nearly daily basis).

Reply via email to