Live data from Hacker News

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

news.ycombinator.com

41–50 of 234 posts

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

#41
post #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

but composition is much, much easier to understand and work with. The article you linked mentions IMHO the biggest disadvantage: One common drawback of using composition instead of inheritance is that methods being provided by individual components may have to be implemented in the derived type, even if they are only forwarding methods Code whose only purpose is to "appease the design" and otherwise does absolutely n…

That isn't an inherent issue of composition though. You could say

   {...students(ajaxDb), ...teachers(ajaxDb)}
to create an object that can handle both students and teachers. Or you could say

   public class StudentsAndTeachers extends Students implements IStudents, ITeachers {
       private _teachers;
       public constructor(Database db, Teachers teachers) {
           super(db);
           _teachers = teachers;
       }
       public getTeacher(TeacherId teacherId) {
           return _teachers.getTeacher(teacherId);
       }
   }

   new StudentsAndTeachers(ajaxDb, new Teachers(ajaxDb));
It seems clear that the features of the language define what is verbose and what isn't verbose. Even the inheritance in the language that encourages inheritance is more verbose than the composition in the neutral language.

(More likely, you wouldn't write this, but every example that is colloquial in inheritance is non-colloquial in composition. The composition oriented solution can be used cleanly with strong guarantees provided to its users; whereas all inheritance oriented solutions are so tacky and hard to use that you will demand a framework with dependency injection which half your team won't be able to understand and will have to treat as magical incantations.)

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

#42
Object oriented programming doesn't really fit every problem. It really seems more strange that it took so long for us to see some alternatives.

I mean, it took over programming like a revolution, like structured programming, but structured->OO doesn't have anything nearly like the benefits of unstructured->structured. It seems like a good paradigm for a couple of problem domains, but IMHO, it got cargo-culted on to everything about mainstream programming without delivering much on the promises it got sold with in regard to increased productivity and code re-use.

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

#44
I think it's probably too early to say there is a trend. There are still traditional OOP languages being created such as Kotlin and Crystal, and not OOP languages have always been created including the ones that inspired this new wave (ML/Haskell for Rust and the Common Lisp for Julia). And even if it's a trend, it might not have to do with issues with the concept of OOP, but for the fact that language creators and early adopters are usually people who are not satisfied with the current established languages (which happens to be mostly traditional OOP), so they naturally favor alternatives models.

All that said, I think it's just that OOP was always broader than the most used languages made it seem. Message passing OOP (like smalltalk, ruby and arguably Erlang/Elixir processes) are not exactly the same as the more class structured OOP (Java, C++, Python) and even before many of those languages there was already the Common Lisp Object System which extended single dispatch OOP to multiple dispatch (and like with Julia, is object.func(args) really different from func(object, args) enough to not be OOP?). In the same way interfaces/traits/abstract classes/composition/dataclasses are also present in OOP languages to handle cases where the model is not a perfect hierarchy of self managing entities, so a language favoring those over inheritance in general is just being more opinionated towards a strategy that was already possible in traditional OOP.

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

#45
post #21

Depending on who you ask, "trend" could be replaced with "progression". I'm with you in that I never really found the OOP style to mesh well with my brain. I always felt like I had to fight it and dealing with massive chains of class inheritance can make it really hard to reason about and change code. I've spent years building web apps with Python and Ruby too. Having only spent a short while with Elixir, I'm finding…

I tend to agree. Due to its sheer popularity, I did some work with OO. In some languages, like Ruby, it has a certain charm.

But in its traditional Gang of Four incarnation (which I encountered years later as a newbie), it felt like an awful lot of ceremony and unneeded complexity to get anything done.

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

#47
OOP is too vague, let's talk about related features which are clear. (To me the 2 most important are inheritance and mutability, I won't mention that "protected" magic at all.)

Inheritance has too easy syntax to avoid "accidental duplication" (pieces of code seem similar on short term but eventually differ on the long run) without creating a new common abstraction to depend on: even before realizing the introduced dependencies are unnecessary but now even deeply entangled. Because in its core what might just happened is "raw" code(text) reuse instead abstraction reuse. "Code duplication is better than wrong abstraction." Or "Write code what is easy to delete."

You might keep adding and adding until you won't be able to substract, because you have to check every dependency back and forth, and there are no layers of abstractions but a constant change of [meaning] with the hope of usefulness in future infinite far away. Additionally intermediate level classes also need names (and meaning...) which makes the naming problem constant and might even blur the clear lines between the originally clear abstractions. The language of our system/domain consists of the relation of individual abstractions, we can't just overload every word and/or litter with unnecessary ones.

It's also a question to decide when to write a class and instantiate instead of just using an adhoc "anonymous" object and use a necessary pattern like factory function or some delegation (like parent class) later if needed. (Ofc. classes might be created later as well, but weird enough it goes the other way around in my xp, maybe its just me, ruined by noob Java 1.6/C# habits gained at the first years of university).

It's too easy to find wrong abstractions with inheritance, too easy to blur good ones, and too hard/exhausting to delete them.

Reflection on the thread: I think I'll focus more on the proper naming of functions "DO"s instead of "WHAT"s, because DOs must have clear intent to drive the design/architecture.

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

#48
OOP was a huge trend in the 90s and I think a lot of devs have learned from experience the ways in which it kinda sucks..

- It doesn’t do great as the code gets older or more complex. Google “fragile base class problem”.

- Inheritance doesn’t do a good job of modeling most real-world problems. Most situations don’t map into a simple “class Dog extends Animal” kind of hierarchy. Steve Yegge’s “the kingdom of nouns” is a great rant on this topic.

- OOP actually requires expert-level knowledge to do right. It seems like it’s beginner-friendly but that’s kind of deceptive. If you’re using inheritance then you should understand Liskov substitution, otherwise it’s not going to work well. And if there’s generics involved then you might need to understand covariance vs contravariance, which is also a beginner-hostile expectation.

Imo, out of the newer languages, I really like Golang’s take. Interface-heavy, no inheritance, and some nice sugar around composition. Dunno if I agree with their lack of generics but I understand the choice, generics create a lot of complexity.

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

#49

Object oriented programming doesn't really fit every problem. It really seems more strange that it took so long for us to see some alternatives. I mean, it took over programming like a revolution, like structured programming, but structured->OO doesn't have anything nearly like the benefits of unstructured->structured. It seems like a good paradigm for a couple of problem domains, but IMHO, it got cargo-culted on to…

One thing I think is OOP works pretty well for GUI type programs. But has little advantage when building networked service infrastructure. So during the desktop era OOP was ascendant. Now we're in a distributed data processing/storage/retrieval/service era. In particular data is ephemeral and not 'owned' by a particular service. So it doesn't make sense to start attaching local methods to it.

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

#50
The ideal language is flexible enough to be multi-paradigm, i.e. it allows you to use OO or procedural or functional etc. as needed/desired, but doesn't force any one of those on you. It gets back to something Paul Graham said[0]: roughly that having "ulterior motives" is a bad trait in a language, and I would consider "getting dogmatic about the paradigm they want you to use" to fall under that. But Rome wasn't built in a day, keep that in mind too, specifically concerning newer languages. Sometimes something isn't there but it's on the roadmap.

[0] http://www.paulgraham.com/javacover.html

Post reply on HN