Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.
Wouldn't it be nice if inside-out objects worked like this?
use base 'Encapsulation';
sub new {
bless {}, shift;
}
sub foo {
my $self = shift;
return $self->{foo} unless @_;
$self->{foo} = shift;
}
1;
If that was the interface but subclasses and other code couldn't reach inside, wouldn't more people use 'em? I believe most programmers violate encapsulation because they're lazy, not because they've gone rogue or something. Here's how to make that work.
Dev vs. live (Score:1)
That gives you protection during testing/development and speed in production (at the risk of REALLY painful bugs if there are flaws in the emulation of Encapsulation.pm).
Alternatively, change the "if" to
Re: (Score:1)
No.
Ovid is throwing away half the point of inside-out objects already: compile-time checking of field names. The other half is being agnostic about the implementation of any superclasses; and your suggestion would mean that one could no longer rely on that, either.
You may as well not use inside-out objects at all. (I am reminded of chromatic’s chocolate cake recipe analogy…)
Re: (Score:1)
That is, the encapsulation hack could be put to an alternate use. Especially if the overload function dies if the caller package isn't isa('Encapsulation').
I agree that the "inside-outness" is not significant in this case.
That's not what I call 'inside-out' objects. (Score:1)
People seem to think that Inside-Out Objects are about not letting other people touch your internals.
They aren't.
Inside-Out Objects solve two out of three problems* I have with traditional Perl OO:
Re: (Score:2)
I've evidently been wrong about IOO. Since the major problem I've faced has traditionally been encapsulation, that was the bit I've focused on. I will have to concede all your points. I just find that virtually every IOO implementation I've seen out there has been painful to work with, so I gave up and hope that solving the major problem I have might be good enough.
Re: (Score:1)
Hmm. For me, the visible difference between hash-based and inside-out objects is turning the following:
into this:
That seems hardly painful… but then, as MJD says, people are weird about syntax.