Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: The world is not object oriented

by demerphq (Chancellor)
on Oct 21, 2007 at 11:59 UTC ( #646254=note: print w/ replies, xml ) Need Help??


in reply to The world is not object oriented

There is OO as a method of encapsulating and associating data and the means to operate on that data, and there is OO as a method of modeling an abstract concept. Both have their place, however I tend to find the latter is actually less useful than the former. The former tends to use 'hasa' or 'containsa' semantics and the latter tends to use 'isa'.

I find programming in an environment that requires isa semantics to be frustrating and annoying (outside of perhaps mix-ins). I tend to find that inheritance and polymorphism to be overused and less useful than is typically advertised, leading to layers of twisty two line subroutines that obscure the actual intent and operation of the code.

On the other hand I find OO as an encapsulation mechansim to be of clear utility, especially in Perl where there are no type declarations. If I build a data structure out of AoAoHoA's and i accidentally feed it to a routine that doesn't operate on that structure the error is neither caught at compile time nor is the error message all that useful, and in fact given autovivification sometimes no error at all occurs, merely incorrect and surprising results. With OO as encapsulation this does problem does not arise, while the error message still will not occur at compile time, an error *will* arise when I call a method on an object that it does not define. Such an error is easy to debug, and is generally preferable to silent erroneous operation.

I think OO is like anything else, used with moderation its fine, used as an end-all-be-all matter of policy is ridiculous.

---
$world=~s/war/peace/g


Comment on Re: The world is not object oriented
Re^2: The world is not object oriented
by tilly (Archbishop) on Oct 21, 2007 at 12:23 UTC
    I agree with you except that has-a is as (or more) useful a tool for OO in modelling mode as is-a is. Therefore when used properly for modelling, has-a is heavily used.

    However I'll agree that there is an awful lot of bad OO out there that overuses is-a.

      Well I'm not sure that we are disagreeing. :-) My point was that the two tend to lean different ways, not that well designed software wouldn't use the most appropriate form of relationship regardless of its intent. Also I guess I was griping a bit, has-a relationships are IMO underused, and IME often more useful than is-a relationships.

      Further to my original point, I think of lot of programmers, especially less experienced programmers (but not at all exclusively), tend to forget that OO can be used simply as a form of encapsulation that makes organizing their code easier. They get so distracted by all the subtleties of inheritance and overloading and polymorphism that they forget that OO can be used in simple ways to achieve complex goals in manageable ways. In fact one of the reasons I like perl and its anonymous subroutines/closures is related to this. Its a simple way to define what is more or less a single method class/object that encapsulates its data conveniently. The classic case is a counter object versus a counter closure.

      ---
      $world=~s/war/peace/g

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (14)
As of 2014-08-28 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (261 votes), past polls