Why Is OOP So Popular?
Find the English version below
Hi ,
Warum entwickeln wir heute objektorientiert und nicht funktional? Wieso sind 7 von 10 der populärsten Programmiersprachen objektorientiert? Und warum ist keine (rein) funktionale Sprache darunter?
Quelle: Stackoverflow Developer Survey 2023
Die Frage hat sich auch Richard Feldman 2019 gestellt. Und die Hintergründe sind interessant.
Natürlich - wie immer - es ist kompliziert.
Aber einen Aspekt finde ich besonders interessant.
Richard fragt sich, ob es an einzigartigen Features in OOP liegt, die in anderen Paradigmen nicht vorhanden sind.
Das einzige wirklich einzigartige Feature von OOP ist Vererbung. Alles Andere finden wir auch in anderen Paradigmen.
Es stellt sich also die Frage: ist Vererbung das Killer-Feature? Entwickeln wir deswegen objektorientiert?
Spannend dabei: Jeder erfahrene Entwickler rät von Vererbung ab. Das populärste Beispiel ist von der Gang of Four in Design Patterns von 1994. Oder in Effective Java von Jochua Bloch.
Prefer Composition over Inheritance
Das ist das Kredo in der objektorientierten Entwicklung.
Vererbung kann also nicht das Killer-Feature sein, dass OOP zum defacto Standard gemacht hat.
Die popularität von OOP war, mehr oder weniger, Zufall.
Alle Sprachen, die wir heute haben sind in einem zeitlichen Kontext entstanden.
Seit Anbeginn der Zeit hat jeder Entwickler nach wegen gesucht seinen Code zu strukturieren. Es wurde schon immer nach wegen gesucht zu modularisieren und zu entkoppeln. Der OOP Ansatz ist einer davon.
Und mit der Zeit spielten viele Faktoren, wie Marketingbudget, populäre Plattformen und Tools, geistige Vorbilder oder einfache Zufälle, wie der Zeitdruck beim Design von JavaScript, dazu bei, dass wir heute OOP als dominierendes Paradigma vorfinden.
Und dabei wissen wir auch, dass OOP viele Schwächen hat. Es verführt zu viel State. Moderne Sprachen verringern das immer weiter. Wir haben fluent-apis, streams und records. Vor vielen Jahren wurden for-each Schleifen eingeführt. Und Features wie Auto-Unboxing, Pattern-Matching helfen uns weiteren State zu vermeiden.
Wenn wir in die FAQ von Kotlin schauen, dann lesen wir:
Moderne Sprachen ermöglichen funktionale Programmierung
Zurück zur Anfangsfrage: Warum entwickeln wir heute objekt-orientiert und nicht funktional?
Zufall. Wir Entwickler streben entkoppelten Code an. Und OOP war zur richtigen Zeit am richtigen Ort. Es half den Code besser zu strukturieren.
OOP ist aber nicht populär weil es das Beste Paradigma ist. Deshalb lohnt es sich über den Tellerrand zu schauen.
Wenn du es noch nicht getan hast, dann setze dich mit der funktionalen Programmierung auseinander. Du profitierst davon. Auch in den populären Sprachen. Du wirst vielleicht nicht alle Vorteile von FP vollends nutzen können (z.B. automatisches memoize). Aber du wirst Code mit weniger Seiteneffekten produzieren - und das ist in jeder Sprache gut.
ps. Mein KKON Talk “Pragmatic Programming mit Kotlin” ist seit letzter Woche auf YouTube 🎉. Darin siehst du ein paar einfache Beispiele, wie ich unnötigen State vermeide. Und das im Live-Coding. Viel Spaß damit!
Rule the Backend,
~ Marcus
Hi ,
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