Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Wednesday September 04, 2002
06:47 PM

Does OO programming suck?

[ #7531 ]

I don't mean that title seriously, of course, but I am really getting discouraged with some of the OO code (and programmers) that I meet. There's one OO developer that I know that, if we discuss a particular programming technique he hasn't used (coroutines, closures, currying, etc), automatically dismisses it as syntactic sugar and replies "I'd just write a class to handle something like that". Syntactic sugar??? Give me a goto and conditionals and I can argue that all of your loop constructs are syntactic sugar.

I've met OO programmers who I would expect, if asked to write "Hello, World", would make it a base class with subclasses to control the spoken language and methods to control the output location on the off chance that something like that might prove necessary.

My brother works with a programmer who is allegedly brilliant, but is so full of design patterns that he takes what should be a simple object model and creates an elaborate superstructure around it to handle every conceivable thing you could throw at it. To his credit, his code apparently works well, but his coworkers loathe him when it comes time to add the feature he inevitably overlooked.

Further, just because -- in Perl -- you bless a hash ref doesn't mean you have OO code. My first big OO project was an absolute piece of junk. Yes, I provided accessors and mutators for everything, sanity checking and used inheritance to avoid code reuse, but essentially I wrote procedural code and used a blessed referent to avoid a global variable. I don't want anyone to see that turkey, but it's still in production and being actively maintained (by me, which I think is an appropriate punishment).

I don't think OO is bad, but many programmers seem to think they've found the holy grail and kind of shut their mind down at that point. Once you've found the holy cup, you can stop searching, right?

I think that, for many programmers, giving them OO is like letting them drive. They forget that bicycles, walking, or not going anywhere are all acceptable alternatives. Unfortunately, just about everything I said above applied to me when I started learning regexen. I had some huge, incredibly complex ones to handle every possible special case that I could think of in these HTML docs I was parsing...

I dunno. Maybe I'm just a freak. I can have data hiding and encapsulation without OO. I could potentially use dispatch tables to simulate polymorphism (ooh...some people will yell at me for that). I might be able to avoid inheritance with cleverly exported subroutines. So why do I use OO? I really like self documenting code and I find that calling well-named methods on well-named objects tends to be self-documenting. My HTML::TokeParser::Simple module uses a factory to achieve this. Call me a conceited idiot (you'll have to take a number, though), but I think that was a very appropriate reason to use OO and a design pattern. There are plenty of legitimate uses for it, but too many illegitimate ones.

Update: /me realizes that he's beginning to sound like an arrogant elitist.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • It's the same thing I ran into in linguistics: no-one wants to have a theory. Those are mundane and dull and too contintent on stupid stuff like facts (like whether [s] actually last a few milliseconds longer in words where it's a plural marker, or yawners like that). Instead, everyone wants to have a METAtheory, with a SPECIAL NEW NOTATION which is ostentatious and trendy, altho no-one will admit it. And if you don't have

    So it is with programming. No-one wants anything as mundane as a list, or a string

    • Dang, that post of mine got partly munged when I pasted it in and posted it. Ahwell, just pretend it's coherent and perfectly spelled and grammatical.
    • They want a plastic fantastic wonderland of classes, and metaclasses, and factory factory factories, and UML, and class hierarchies CRAP.

      Heh. The UML reference reminds me of a funny incident that perfectly illustrates it. I was in a meeting with the "syntactic sugar" guy and our boss drew out a rough network diagram showing the various parts of of a system we were building. The boss making the drawing asked "did you get all of that?" and SyntacticSugarGuy replied "yes, but I drew it in UML."

      On the

  • I think this falls in the category of 'there are no silver bullets', not even OO.
  • I'm really glad I'm seeing comments like yours.

    For years people glommed on to OO as the sure cure, the fix for all your programming woes. The same thing has happened repeatedly, starting at least in the '70s with "structured programming". You still hear "goto should be banned" repeated without thought.

    In every case, the net effect of the introduction of the technology has been positive, but only after people have settled down some and realized there's no magic in it. But in the beginning the buzz has a