Slightly Off KIlter

Normal is overrated


Why OOP?


I had an interview yesterday. The company uses Perl (specifically,
object-oriented Perl) and C++. The job would entail working with OO Perl.


Now, I have some OO background: I worked at Taligent for 2 years. I’ve read
the books. I understand the terms. I’ve used OO Perl modules.


That said, I haven’t written a lot of OO Perl myself. I don’t think I’d have
any difficulty writing code this way (I never had trouble doing new things in
Perl). Also, I’d like to improve my skills at using OO Perl because, well,
because it’s there. It’s popular, it’s different, “everyone is doing it”.
OOPerl would provide a different set of spells in my programming grimoire (I
was going to say “weapons in my arsenal” but decided I didn’t care for that
metaphor).



The interview didn’t go very well. I’m afraid I lost a lot of points when I
gave an honest first answer to one of the questions I was asked (Oh well,
I’ve long ago given up lying in interviews in order to “look good”; it’s too
much effort for too little long-term gain :/


But the hiring manager asked “Why would one use OO techniques to solve a
problem?”
and I answered “Because the manager wants to use OO for that project”.


Duck.

Sigh.

Well, it was an honest answer. (If not the “best” answer in an interview situation 😦


So… why _would_ one choose to use an object-oriented approach? Unless the
“objects” seem to fall naturally out of the project (in data filters, which
is what I usually do, there aren’t a lot of obvious falling objects).



    Encapsulation? I try to keep things encapsulated in my “procedural code”


    Abstraction? How so different?


    Modularity? I write functions. I use libraries and modules.


    Data protection? I tend to do that anyway…


    Namespace cluttering? That can be handled procedurally, using modules
    “correctly”.




I was reading a book called “Headfirst Java” and they gave an example of a
project in which Mr. Oop “chose better” because he could better handle
changes to the spec than could Mr. Procedural. But, as I read the example, it
seemd to me that with a slight rewrite (a different way of changing the
spec), Mr. Oop would have had more to change and Mr. Procedural would have
come out ahead.


I’m afraid I’m of the “neither is better, both are good; the best thing to do
is to write clean, maintainable code” school. I also understand that “for
every 10 people you ask about Object-oriented programming, you get 10
different answers”. However, I am willing to be educated.


How would you have answered the interview question?

When and why would you choose to use OOP design and implementation over
procedural code?

What sorts of problems are best/better suited for OOP solutions?



One response to “Why OOP?”

  1. At a job interview they asked me the same, I always feel sorry for the poor fellows who think OOP will make them a better programmer.
    It really wont. You are either good or not, no paradigm will help you. I am rather ased to solve the problem than maturbate over my code yelling, look, I fcking have classes and sht.

    Like

Leave a comment