Functional rulez, OOP sucks?

I am a pretty laid back guy, but lately I have started getting a bit worried about the state of programming, or more specifically loud mouthed blog-wielding programmers. I have seen so much stupid shit floating around that I feel it is my duty to stick an IBM Model M keyboard in the ground and wave the flag of Sanity in peoples faces.

It seems that quite a few programmers have discovered a “new” paradigm called Functional Programming, and suddenly it has become fashionable to dismiss Object Oriented Programming as the Old Way To Do Things.

Articles with titles like “Why OO sucks”, “The faster you unlearn OOP, the better for you and your software” and “Object Oriented Programming is an expensive disaster which must end” have been floating around the internet gaining vocal followers.

These articles zoom in on specific aspects of OO paradigm and try ripping them apart.

Apparently:

  • Inheritance sucks because deep hierarchies make for fragile base classes.
  • Multiple Inheritance sucks because you could get diamond-shaped inheritance hierarchies and non-deterministic inherited function calling.
  • OO sucks because modelling problems as classes and objects doesn’t always seem natural.

Some of the claims are pretty accurate, but any sane programmer knows how to avoid these pitfalls and corner cases for the most part. There are pitfalls in any programming paradigm.

Still, according to some newly enlightened functional zealots, Object Oriented Programming is bad, evil, broken, and it’s proponents have been lying to us. It must be ridiculed and thrown away.

Nothing good has ever been made with OO!

Or has it?

Well, yes… Most of the software written since the late 90’s was written in an OO language, until browsers started fixing their JavaScript engines. Some of these software projects are pretty massive. Windows, OSX, iOS, Android, Chrome, Safari, Firefox, Oracle, MongoDB, and so on.

I am a language-, paradigm- and OS-agnostic guy. I have preferences, but I don’t have a problem working in a non-preferred language or OS as long as I have the right tool for the job.

The thing that irks me is programmers slagging off OO because they just jumped ship to Functional, thinking that it is something new and awesome and better than OO. Functional and Object Oriented programming were invented in the 50’s. That is about 70 years ago, and they didn’t really catch on until much later, because procedural programming was all the rage at least until the 90’s when OO was popularized through Java. Functional programming hasn’t yet seen the same popularity as OO, but has been in use through Lisp, Scheme, and later Haskell, Scala and Clojure among others.

The funny thing is that you will find the same kind of crazy blog posts from the early 2000’s slagging off procedural programming and putting OO on a pedestal.

In fact, languages such as Java, C# and JavaScript have started adding functional aspects, and are going multi-paradigm. Why could that be? Maybe because one paradigm can’t solve all problems?

Functional programming definitely doesn’t solve all problems, at least not in any easily comprehensible or intuitive way, or it would have become more popular in it’s 70 year history. I think the only reason it is gaining in popularity now is because for certain problems it is a good match, and as software gets more complex it seems less of a burden to use some functional programming paradigms.

I am glad that several major programming languages are including functional aspects. And I also believe that most programmers would benefit from learning as many languages and paradigms as possible. Just leave the elitist bullshit at the door. If your reason to use functional programming is that you can make a one-liner that solves all sorts of shit, then remember someone else has to read that incomprehensible mess later. Programming is not a write-only activity, and programmers are supposed to solve problems, not create new ones.

Now get off my lawn!

Leave a Reply

Your email address will not be published.