I guess I wasn't asking if it would be "possible" (I think that's been
established), but if it would be "easy", "reasonable", or "clean" (as it
appears to be in Python, although I'm just going by what the quoted web page
says). I recall some discussions about the "best" way to this in Perl 6,
but don't recall if it converged on anything nice.
Anyway, I thought it was interesting to see the ease of "forward
compatibility" for simple attributes touted as a feature of Python. I'd
like to tout it as a feature of Perl 6 too, because I also hate writing
getters and setters... :)
-John
Anything can be anything. I'm sure that despite the ability to run all
the code you want upon reading/writing an attribute, some people will
still write setters and getters.
Would it be Perl if it dictated any of these approaches?
Juerd
"In Java, you have to use getters and setters because using public fields
gives you no opportunity to go back and change your mind later to using
getters and setters. So in Java, you might as well get the chore out of the
way up front. In Python, this is silly, because you can start with a normal
attribute and change your mind at any time, without affecting any clients of
the class. So, don't write getters and setters."
I'd like to be able to s/Python/Perl 6/ above, but after many discussions on
this topic, I'm still not sure if I can.
-John
Of course it's a feature. Having lvalue attributes means you don't have
to replicate all scalar lvalue methods to get all functionality without
copying. IMO, This is even better than in Python, with its constant
variables.
Let me demonstrate:
$foo.bar .= "foo"
$foo.bar ~~ s:e/foo/bar/;
$foo.bar.=reverse;
my $quux := $foo.bar;
$quux = 1;
versus:
$foo.set_bar($foo.get_bar ~ "foo");
$foo.set_bar(do { (my $temp = $foo.get_bar) ~~ s:e/foo/bar/; $temp });
$foo.set_bar($foo.get_bar.reverse);
my $quux # ... ehm, right. Let's see. I think it's something like:
will STORE { $foo.set_bar($_) }
will FETCH { $foo.get_bar };
$quux = 1;
Juerd
Meant ~= there.
Juerd
Wow, that's a blast from the past. I wonder how much of it is still
valid... :)
-John
Almost all of it, except for details like "is public". Just because
A12 didn't come out till this year doesn't mean we weren't talking
about those things ever since 2000. I knew that attributes wanted
to look like $.foo since before Apocalypse 1, for instance.
Larry
It converged on "the core-like way returning an anonymous object with
STORE and FETCH methods is ugly, but it should be easy to provide nice
wrappers around it." Those nice wrappers are probably going to end up
in the standard dialect.
Perl 6 is going to be better with opacity than any other language I know
of. We're aware that lying about what's really going on is a useful
thing to do. So we give you the chance to be as poker-faced about your
internals as you like.
... Not that the user can't read your ass if he tries hard enough :-)
Luke
Amen.
Which reminds me, what ever happened to POOL? You there, Simon?
--
Mark REED | CNN Internet Technology
1 CNN Center Rm SW0831G | mark...@cnn.com
Atlanta, GA 30348 USA | +1 404 827 4754