Share via


Is object oriented programming good?

When we use a tool for a long time we get used to it and think in its terms rather than using it to help materialize our thoughts. Mostly this is not a good idea.

We were taught OOP in college and kind of told that even though functional programming sounds cool its only for funky stuff you never use in real life. We were told that dynamic languages were good for scripting and its too slow to use for real life projects. Soon we started believing in these stories. 

Everything was going on fine, until I attended a training from Alexandar Stepanov couple of years ago. He is widely known as the father of generic programming and one of the key person behind C++ STL. Funny part is, in the training he started ridiculing the whole premise of OOP. His point was that computing consists of applying algorithms to data. So algorithms comes first and that is the key part in programming. He suggestes thinking in algorithms and not in terms of objects. If you ever used C++ Standard Template Library (STL) you must've noticed the perculiarity. The whole of STL is not OO. It talks about applying algorithms to containers. STL code looks like sort(v.begin(), v.end()); Not like v.Sort(); as one would expect in a OO system.

I highly recommend reading his interview here where he talks about his thoughts on this.

Object oriented system is frequently taught with examples like Employee, Employer, Car, Animals. I think as these examples suggest they are more suitable in business applications. If you are writing an kernel or maybe writing a Test suite (like I am) they make less sense. You want to be liberated of the burden of always thinking in objects and rather concentrate of the algorithms you need to implement.  

With time I have started coding seriously on functional and dynamic languages. The more I use them, the more they seem natural.

Comments

  • Anonymous
    December 21, 2006
    In languages that are 'very' OO, methods/functions themselves are objects, so you can use procedural and OO at the same time.  There really isn't a huge difference - objects give polymorphism - so if you have one type of data that sorting means one thing for, and another type of data where it means something else, then it might make sense to make the sort method be part of that object.Dynamic dispatch (the visitor pattern in languages that don't support it natively) can be used to 'tack on' extra methods.  Mixins might also be useful for this.Like it or not, v.sort() is more intuitive than sort(v) - people prefer the idea that objects know how to handle themselves.  Of course, the reality is often different, and objects with lots of behaviour become hard to maintain - with mixins, etc., this might be worked around.I'm a Java programmer who keeps data and behaviour separate where possible.  Most of my interfaces are single-method.
  • Anonymous
    December 21, 2006
    The comment has been removed
  • Anonymous
    December 21, 2006
    Ricky I am not very sure about whether v.Sort is more intuitive than sort(v,..), the question is very subjective and I might say since I'm appyling the sort alogrithm to daya sort(V) is more intuitive.Its true that with dynamic dispatch (or mixin or extension methods you can write tack on extra methods. But most programmers get thoroughly confused with Mixins and extension methods. I further believe Mixins don't scale up to large projects. Anyway mixins are not supported on .NET (see http://blogs.msdn.com/abhinaba/archive/2006/01/06/510034.aspx#522438 for why)
  • Anonymous
    December 22, 2006
    When looking at sort(v) rather than v.sort(), there is the question of where sort comes from.  Is it the best one for that particular v?  I don't know.  v.sort(), where v is responsible for sorting itself, I know that it's the one that v has chosen for itself.  It involves less lookup for me.I've never used mixins - it appears that Scala supports them, it's statically typed, and it can run on .NET.  Remember that .NET is not a language.  The blog you linked to was about some language called C#, but any new language that includes goto is worthy of ignorance. ;)
  • Anonymous
    November 07, 2007
    My question:  if I were designing a VERY  scalable website from scratch....would i want to use object-oriented programming, or would I want to avoid it?  Would OOD increase or decrease the development time, and would it increase or decrease performance?   Let's use PHP as an example.  I can declare lots of scalar variables and methods, or I can define a 2-3 level hierarchy of objects.  What are the pros/cons of OOD vs non-OOD? Thanks