Live data from Hacker News

Ask HN: Why do new(ish) programming languages eschew OOP features?

news.ycombinator.com

1–10 of 234 posts

Ask HN: Why do new(ish) programming languages eschew OOP features?

#1
Some relatively new or popular languages are not object-oriented, although they may have object-like features. Examples include: Rust, Go, Julia, Nim.

I have always struggled with OOP and have never found it a natural way of programming. But many other programmers will disagree of course.

I find it fascinating that some new languages have chosen to eschew the OOP model. Why do you think that is? And what do think of this trend (if it is indeed a trend)?

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#2
Imho, OOP is part of a greater puzzle.

There are domains where OOP fits perfectly, there are domains where functional programming fits perfectly, there are even domains where imperative programming fits perfectly.

We're constantly searching for the perfect fits-it-all solution which we haven't found yet. From my POV this is why there are some competing standards, which all have their merits but on a first glance exclude each other.

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#3
OOP made for great tool sets, training seminar and other products. But the mentality of "circle the nouns in your requirements" is stupid, and serves nobody. Programmers analyze they're requirements into code and data, and those things have little bundling to one another or the requirement domain.

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#4
Maybe because traditional OOP is already well represented by popular languages with large ecosystems? Creators of new languages want to do something new.

There is Elixir / Erlang which many consider to stick more closely to the original idea of OOP.

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#5
Unpopular answer: pure fashion.

There's nothing wrong with object methods (that's 100% pure syntax vs. a function call) and an implicit "this" scope for symbols (which is just a limited form of dynamic scope[1]). They don't make code hard to understand. OO can be abused to produce bad designs, of course, but that's not an indictment of its syntax.

Non-syntactic aspects are maybe a more involved discussion. For an example, I personally think traditional OO lends itself very nicely to runtime polymorphism. And this is something that more modern languages have really struggled with (take a random new hacker and try to explain to them virtual functions vs. trait objects). Now... polymorphism can be horribly abused. But, it's still useful, and IMHO the current trends are throwing it out with the bathwater.

[1] Something that itself has long since fallen out of fashion but which has real uses. Being able to reference the "current" value of a symbol (in the sense of "the current thing we are working on") is very useful.

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#6
Inheritance makes some sense, but composition is much, much easier to understand and work with. Inheritance has well documented problems that composition does not. It’s not so much about being object oriented or not, at least not directly.

I could elaborate, but others have said it better anyways.

https://en.m.wikipedia.org/wiki/Composition_over_inheritance

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#7
A big change in my life was reading the Tao of objects -- https://www.amazon.com/Tao-Objects-Gary-Entsminger/dp/013882... along with the great Coad-Yourdan OOA/OOD books -- example: https://www.amazon.com/Object-Oriented-Analysis-Yourdon-Comp...

The premise was great. We reason about things as real-world objects, if we organize our code the same way, we can reason about our code.

Twenty-plus years later, In practice, however, I'm given a graphics object with a DisplayText method. It has three parameters, two of which are optional. If I call it with text I want displayed? It is an extremely rare event that what I wanted to happen, happens.

It gets much worse from this simple example, with versioning, monkey-patching, and overloading (ouch!). Add in multiple languages using the same codebase? Mutable code?

The maintenance programmer is left with a general concept. Under that concept there is code. Whether that concept maps to the concept the users asked about, or what changes in state that code makes? Nobody knows.

It's worse than bad. The incoming programmer is given concepts he thinks he can reason about, but which rarely match what's actually happening.

To combat that, the OO-mutable guys have gone to TDD. Test-first, then code.

That's a survival skill in modern programming, but all it does is change the definition of "What is a foo?" from a free-wheeling conversation to a concrete executable set of tests. And that is assuming you use it everywhere.

OO was a big-picture, conceptually-simple way of organizing code for big projects. We had a bucket for everything.

We ended up with hundreds of buckets that were confusing and we were never sure what belonged where, or if we touched one thing what other things might happen.

Functions, however, remained very simple. No matter what the function does, is it something you want or not? As long as you keep it simple and immutable, over time you keep building up and honing a reusable set of functions: tokens describing important things you want the system to do. As it turns out, quite surprisingly to me and others, reasoning and simplifying around what you want the system to do is much more productive and easier to understand than reasoning and simplifying around what you want the system to be

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#8
IMO they just expose more of how OOP really works, giving you flexibility.

Take Rust. Just because I like their pragmatic approach. They represent objects as structs with functions attached that have access to the struct data. In C++, Java, etc this is roughly how objects actually work underneath.

They eliminate inheritance, replacing it with interfaces. Exposing the objects for what they really are, structs with functions attached, makes this strategy easier.

Traditional OOP, especially with multiple inheritance, tends to encourage nested objects (structs) that become hard to reason about.

Another related innovation has been structural typing. Typescript is great with this. Essentially, if you have two "objects" with the same fields, you can assign them to eachother freely. Typescript doesn't care if they actually inherit from eachother. If the interface signatures are compatible (matching fields, matching types), they can be freely used in eachothers place. This is great for constructing anonymous objects to pass off without all the cruft, basically just Json fields.

TLDR: newer languages decided that if two objects look like ducks they are both ducks, even if you decide to call one something else. Because who really cares what you name your ducks or which ducks they inherit from. This breaks from traditional OOP by loosening the rules of inheritance, but so far it's been a boon for productivity (for me at least)

Re: Ask HN: Why do new(ish) programming languages eschew OOP features?

#9
For a long time, abstraction was the name of the game. OOP is the most popular way to achieve a higher level of abstraction.

Programmers have noticed that infinite abstraction was not necessarily a good thing to have (or an easy one to achieve with a good design).

They had neglected alternative paradigms and lower level languages. They had hoped to just abstract C away, and forget about it. Now they want to replace C instead of abstracting it away.

Post reply on HN