Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Hmm...

by SpanishInquisition (Pilgrim)
on Sep 21, 2004 at 16:58 UTC ( [id://392713]=note: print w/replies, xml ) Need Help??


in reply to "if" Considered Harmful in OO programming

Deeply chained ifs are ugly in ANY coding style. One point may OOP advocates miss is that inheritance and polymorphism are often just drawing out a simple if or for loop or whatever and obscuring it exists. Often, this makes it worse and designs can be 5x longer in LOC and actually less readable (ever heard the phrase "Java is readable -- like a phonebook?").

What we have is a simple coding error that could have been tamed in other styles as well, such as adding a function to check for tags of certain types. In fact, the thought to make that a function would have been more readily obvious in a functional paradigm, at least I think so (i.e. short functions that build on other functions so everything works like magic).

Liberal use of objects can be a good thing, but using polymorphism or inheritance to defeat an if statement is suicide. Beer is good in small amounts. Objects are good in small amounts. Know your limitations.

<quote> This section has presented numerous rules for staying out of trouble with inheritance. The underlying message of all these rules is that inheritance tends to work against the primary technical imperative you have as a programmer, which is to manage complexity. For the sake of controlling complexity, you should maintain a heavy bias against inheritance. </quote>

100% Agreed! Thank you people for backing me up! I'd print this out and put it on my cube wall, though everyone here at Innotech would stone me for those beliefs. I'm already a black sheep though... (baaa!)

Replies are listed 'Best First'.
Re: Hmm...
by bwelch (Curate) on Sep 21, 2004 at 17:25 UTC
    Well said! Objects are good when they help.

    When I was learning java and OOP, it was fun. However, it was soon easy to use OOP features where they really weren't helpful just to 'use the advantages of OOP', leading to code that wasn't good.

    All things in moderation...

      You're not railing against the OO way of doing it, you're railing against the idiotic Java way of doing it. Take a look at Smalltalk, where even the simplest 'if' statement is implemented using a message polymorphism on the Boolean class for examples of this sort of thing Done Right.

      Of course, you can only really do it right if you're in a language which has blocks/anonymous subroutines, which is where Java falls down.

      All things in moderation...

      I have a close friend who gave me the best advice. She's a nutritionist, but the idea applies to most situations:

      Everything in moderation, including moderation.

      require General::Disclaimer;

      All code, unless otherwise noted, is untested

      "All it will give you though, are headaches after headaches as it misinterprets your instructions in the most innovative yet useless ways." - Maypole and I - Tales from the Frontier of a Relationship (by Corion)

        Moderation in moderation? If that allows for running amok periodically, I'm all for running amok.

        Naaaaaaaaaaaaarf.....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 15:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found