Live data from Hacker News

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

news.ycombinator.com

21–30 of 234 posts

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

#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 semi-complicated topics and patterns to be a lot easier to digest even with no formal functional programming background.

Like just today I watched a talk where a guy live coded a web framework DSL in about 30 minutes[0]. One with a beautiful API for controllers and a router. It was a total head explode moment for me (but not in a bad way, it was like seeing the light).

I'm still a newbie with functional programming but so far it feels much more like a WYSIWYG style of programming where your domain is front and center where with OOP it feels like you're bombarded with purposely confusing legal documents and fine print with a small bit of your domain thrown into the mix.

[0]: https://www.youtube.com/watch?v=GRXc-jKRESA

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

#22

If you'd like to hear the case against OOP in modern programming, the Rich Hickey talks are a pretty good place to start: * The value of values * Simple made easy * Are we there yet? I'm on mobile, but you'll find these easily on the google.

For anybody looking to broaden their programming mind, I highly recommend those talks.

They are given by the author of Clojure, but Clojure is hardly a prerequisite to many of his talks.

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

#23
Mostly because it's generally recognized that inheritance was a bad idea. "Prefer composition and interfaces over inheritance" and such.

Also because mutable object state is problematic--it makes a large system harder to reason about and certan types of bugs more likely, and makes thread safety very difficult.

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

#25
post #19
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

Composition should be favored over inheritance whenever feasible. It is not always feasible so many use for inheritance remain. What you can do is make composition easier. Kotlin does this with its delegation system: https://kotlinlang.org/docs/reference/delegation.html

Of course, it is possible to totally eschew inheritance as a language feature. Go does it nicely and I can’t think of many circumstances where modeling my code has suffered as a result, usually the opposite.

That said I don’t claim inheritance to be useless by any means, and I would not use Go for every kind of software.

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

#26
Are they avoiding OOP or classes? With some of these languages (Rust, also Swift) you have OOP without using classes. Here is a good video explaining the benefits of using structs and protocols with swift, which are similar to structs and traits in Rust. (WWDC 2015 Protocol Oriented Programming in Swift) https://www.youtube.com/watch?v=g2LwFZatfTI

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

#27
Many systems people want to build with computers cannot be easily conceptualised as graphs of largely self-contained objects, interacting through swapping messages. These problems instead revolve around complex data processing, and are more easily conceptualised as data flowing through a network of functions, and into and out of containers.

It is possible to build these systems using OO, by reifying the network of functions and the data into objects. But all you are really doing is reinventing functional programming with a layer of OO cruft on top of it, and it is always going to be easier to build the equivalent system in a language that lets the functions and the data structures be unencumbered.

For programming tasks that actually are best conceptualised as objects, OO works quite well. These usually involve the provisioning of some largely static virtual environment, such as a UI, game world, or inversion of control container. Here, objects are long-lived, genuinely independent, and interact in well-defined ways via actions and events, usually swapping only small pieces of state.

My guess is that the advent of GUIs and sophisticated games in the 80s and 90s pushed programmers to be more interested in this latter type of problem, and this was reflected in the languages that evolved. Then the advent of the internet and machine learning in the 2000s and 2010s revived interest in data processing and data flow, and so language design began to shift back.

I suspect in 100 years, if humans are still doing any programming, all popular languages will be mixed-paradigm, and the question of OO vs functional will simply be a blend decided by needs of the problem at hand, rather than the kind of dogmatic arguments of this era, which will be viewed through a historical lens as rather quaint and silly.

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

#28
Because OOP is a good idea that's been ridden into the ground by dogmatic implementations.

OOP is fine, and it makes sense for lots of things. But going crazy with OOP makes for a mess, and a lot of software and languages and tools have chosen "let's do OOP" over "let's do good software". So non OOP stuff is just the natural backlash to OOP gone wild.

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

#29
I'm not sure. As someone who's mostly self taught I don't really understand the big deal either way. I mostly learned about the idea behind oop while trying to implement my own classes using metatables in lua and trying to manually deal with problems languages with built in classes deal with for you.

I like the idea of encapsulating functions with data and like the ability to inherit to subclasses. I don't really like languages like java that enforce oop at the language level. I prefer languages like D, python or c++ that offer it as a tool but don't restrict you to writing strictly oop code. I find D's class implentation to be the simplest to understand. With classes being reference types with inheritence and structs being value types lacking inheritence. It makes it clear to me when a type should be a class and when it should be a struct or some other data type.

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

#30

Earlier quoted context omitted.

It's "pure fashion" until you try to massage your new subclass into behaving slightly differently when you're living with class hierarchies that are N levels deep. Clean compositions, ala Scala traits, can be done with OO. It's just not something I've seen in the wild, or something actively encouraged by any OO teachings I've witnessed. At the same time, composition is pretty much the only way FP is taught (at least…

This, basically. People should stop thinking about "composition vs. inheritance" and start thinking of implementation-inheritance and thus OOP in a strict sense as "composition plus open recursion". Open recursion (viz. the fact that methods defined on your "base" classes can invoke 'virtual' methods on self and end up depending on behavior that may have been overridden at any level in the class hierarchy) is quite o…

Open recursion is pretty much core to the most useful OOP idiom, which I would assert is UI component toolkits.

UI heavily relies on a large number of conventions that the user learns to expect to cat in certain ways. You can parameterize a UI widget that encapsulates these conventions with function pointers or overridden methods, but the end result is pretty much the same.

I'll strongly agree however that far too few programmers in OO languages pay enough attention to the hard problem of designing for extension. It's the reason that C#, unlike Java, defaults to non-virtual methods.

Post reply on HN