Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Perl 5 OOP solutions

by xdg (Monsignor)
on Apr 15, 2006 at 13:11 UTC ( [id://543529]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Perl 5 OOP solutions
in thread Perl 5 OOP solutions

The need for strong encapsulation is (IMO) overblown. In many of the application domains where perl thrives, it is not really needed, and if you do find you really need it, you probably shouldn't be coding in Perl anyway. Of course encapsulation has a social component to it as well, a "keep out the dumb programmer next to me" feature. But honestly, I think that issue is better addressed by social policy than by language features.

The point I make in my Inside-Out tutorial presentation is that people frequently mistake encapsulation for hiding information. I see encapsulation as insulating users and subclassers of a class from its implementation. Social policy can work within a team, but it doesn't help when Module::X on CPAN that you subclass suddenly switches from hash-based to array-based (or inside-out) implementation.

As for substitutability, a well designed class will not have this problem. In fact I can break substitutability in just about any language, although languages with strict type systems are harder than dynamic languages like Perl/Python/Ruby/etc.

I see this as more related to the first point. Consider all the mess that UNIVERSAL::can/isa play with things like Class::Adapter -- substitutability needs to be at the interface level, not the blessed or reftype level.

The "namespace clashing" is a little ambiguous, it sounds to me like a C++ism and really just another word for encapsulation.

Yes and no. Within Perl and in reference to hash-based objects, I think this refers to how keys within a blessed hash can clash between super/subclasses. That is an encapsulation issue, but the way it crops up even without changing the type of the blessed reference is very specific to the history of how objects are created in Perl.

I actually think that a meta-level infrastructure like Class::MOP might be just what inside-out objects need to help reduce that complexity. By moving the complexity up the meta-chain, you move it out of the view of the casual user, and still keep it accessible to those who need it.

I need to understand Class::MOP and how it's used for Moose much better, but from what I saw in trying to understand Moose's capabilities, I have a sneaking suspicion that it might be possible to wrap Class::MOP around Class::InsideOut without too great a struggle. (Things like serialization might become interesting.)

-xdg

Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://543529]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found