Why Is OOP So Popular?
Author
Marcus HeldHi,
Why do we develop object-oriented today and not functionally?
Why are 7 out of 10 of the most popular programming languages object-oriented? And why is there no purely functional language among them?
Source: Stackoverflow Developer Survey 2023
This question was also asked by Richard Feldman in 2019 . And the backgrounds are interesting.
Of course - as always - it’s complicated.
But one aspect I find particularly interesting.
Richard wonders if it’s due to unique features in OOP that are not present in other paradigms.
The only truly unique feature of OOP is inheritance. Everything else we also find in other paradigms.
So the question arises: is inheritance the killer feature? Is that why we develop object-oriented?
Interestingly, every experienced developer advises against inheritance . The most famous example is from the Gang of Four in Design Patterns from 1994. Or in Effective Java by Joshua Bloch.
Prefer Composition over Inheritance
This is the creed in object-oriented development.
Inheritance, therefore, cannot be the killer feature that made OOP the de facto standard.
The popularity of OOP was, more or less, by chance.
All the languages we have today emerged in a temporal context.
Since the dawn of time, every developer has been looking for ways to structure their code. There has always been a search for ways to modularize and decouple. The OOP approach is one of them.
And over time, many factors, such as marketing budgets, popular platforms and tools, intellectual role models, or simple coincidences, such as the time pressure during the design of JavaScript, contributed to OOP being the dominant paradigm today.
And we also know that OOP has many weaknesses. It tempts to have too much state. Modern languages are increasingly reducing this. We have fluent APIs, streams, and records. Many years ago, for-each loops were introduced. And features like auto-unboxing, pattern matching help us to avoid further state.
If we look at the FAQ of Kotlin , we read:
Modern Languages Enable Functional Programming
Back to the initial question: Why do we develop object-oriented today and not functionally?
Chance. We developers strive for decoupled code. And OOP was in the right place at the right time. It helped structure the code better.
OOP is not popular because it’s the best paradigm. That’s why it’s worth looking beyond the horizon.
If you haven’t done so yet, then engage with functional programming. You will benefit from it. Even in popular languages. You may not be able to fully utilize all the advantages of FP (e.g., automatic memoization). But you will produce code with fewer side effects - and that’s good in any language.
P.S. My KKON talk “Pragmatic Programming with Kotlin” has been on YouTube since last week 🎉 ( Talk is in German*). In it, you’ll see a few simple examples of how I avoid unnecessary state. And all in live coding. Enjoy!*
Rule the Backend,
~ Marcus