Live data from Hacker News

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

news.ycombinator.com

161–170 of 234 posts

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

#161

I was a big fan of OOP in theory when I learned it in the 90s and I still use it quite often, but in practice, any sizable OOP codebase that I've had to work with is _way_, _way_, more difficult than a non-OOP codebase that just directly solves the problem in a straightforward way. OOP encourages adding layers of abstraction, indirection, and generic stuff that sounds great if you're trying to create some kind of gen…

Generic programming is not same as OOP. Both Rust and Julia have extensive generic programming capabilities, arguably more powerful although less complicated than template meta-programming.

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

#162
post #150

Earlier quoted context omitted.

C++ is OOP, though.

C++ is multi-paradigm. While people can write OOP code in C++, they can also write header-only libraries, which is generic programming. In C++ generic programming, inheritance is merely a language feature to get what you want, not the main method of abstraction.

You can do that in C, though. C++ was originally "C, with Classes", so OOP was the whole point of C++ existing in the first place.

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

#163
Nearly all the discussion here is about inheritance.

I think the main advantage of OOP is message passing - which, if you think about it, is pretty how networking works across the board. (This also makes sense if you think about Smalltalk's heritage).

Basically - if I send a message to a networked server - as long as my message is in the correct format and I send it to the right place - then I don't care about the implementation at the other end.

The fact that I send a GET request to HAProxy that analyses it, routes it and then passes it to Nginx that embellishes it and passes it to some application server that actually does the work is OOP in action. As the message sender, I need to know the protocol (message format) and where to send it - and that's it. The fact that the implementation goes through three layers and does who knows what is irrelevant.

The trouble is people looked at Smalltalk and took the wrong bits to be important (just like Steve Jobs did when Apple designed the Lisa GUI).

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

#164
> I have always struggled with OOP and have never found it a natural way of programming.

'Modern' OO languages are never natural. Actors are more natural.

A typical day-to-day Java Spring web service workflow:

1. Receive request in Controller.

2. Get FooRepository in through DI.

3. Read a user from UserRepository (behind UserRepository is a SQL database).

4. Get another stuff from DI, say EmailService.

5. Call EmailService to send email based on properties of Foo.

6. Return OK to the client.

Let's see what's in the example:

1. Controller/Repository/Service/Container/Request are not objects. They are made up engineering concepts.

2. The User seems to be a reasonable object, but actually, it's not. It's dead, it only temporarily revives when you summon it from the database, then becomes dead again. It does not know how to do things, it cannot even repeatedly check the current time and then send email itself just like any person in the real world. In contrast, actors are mostly long live in-memory processes and can tell anyone do anything at any time.

Why it's bad or I should say, redundant?

1. Consider Controllers, Services or other objects, if you have 100 methods on a single class it's considered a code smell. Then guys in the project will refactor it to 10 different made up classes with 10 methods each. The name of the classes and their relationships to methods are totally arbitrary, 10 people will yield 10 totally different results.

2. The User is just data, there is no point in make them objects. A) The OO has an in-memory reference system but it's awkward when combining with database entity ids or any kind of distributed environment. B) OO class is redundant because struct or algebra data type (ADT) will do, and they have much better semantics on equality. C) When it comes to modeling OO is more awkward than ADT (because there's no sum type). When it comes polymorphism (the main advertised aspect of OO) the sub-type polymorphism is more awkward than parametric polymorphism.

Personal conclusion (at least in the Web scenario): Functional style (ADT + functions) is simpler. Actor style is intuitive for the real-time web system. 'Modern' OO is both awkward and redundant because no one is doing OO in web programming anyway.

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

#165
post #150

Earlier quoted context omitted.

C++ is OOP, though.

No. OOP is just one aspect, but the most popular one.

I wonder how much of this mess is because people get introduced to these concepts(Generics etc) through wrong languages.

Now, there is a very similar problem with concepts like recursion. Even Algorithm, DS and problem solving in general. You never get to learn this stuff well because you get drowned in syntax juggling, type headaches, absence of good features to do recursion, first class functions, mutability, closures, pattern matching, and data handling etc well.

I find learning these things in ML or Lisp languages simplifies the problem to a great extent. You basically learn to how to solve problems and then how to use the right tools to solve the problems. Instead people chose tools that send them solving infinite sub problems to arrive at solving the real problem. Most people tune out, and rightly so. Efficiency comes after correctness in any approach. And you should never optimize for speed to begin with.

Most people getting introduced to programming in Java/C++ are generally digging through layers and layers of code trying to do what should be done simply in a straight forward way. This is often made more complicated by addition of frameworks and opinionated way of forcing people doing things in a way that requires them to go and read and work through an entire history of software literature. All the while you could just write code to solve the problem.

Design Pattern abuse is very common in OO world. And people for some reason like to write a lot of code sometimes for something as simple as writing a few lines of code.

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

#166

I think there are many useful ideas in OOP languages and I still struggle with purely functional languages, I think/hope we'll see increasingly mixed model languages. I'd be interested to see a language like C# but with: + Immutable by default. + 'Free' functions, so they don't have to be in classes. + No inheritance. + Some sort of distinction, and I'm not clear how it would work yet, between data objects (immutable…

Agree about immutability (I would love to have “readonly” to be applicable to classes), but I like the current static classes approach.

It’s a single keyword, the language guarantee you won’t have any instance fields or methods in these classes.

Global functions pollute namespaces, and auto-complete index. Static classes provide local namespaces for these functions, they also hide implementation details. I sometimes implement moderately complex pieces of functionality as a static class with just a single public method, the rest of the code is in private methods. These private methods don’t show in auto-complete in outside code, even if they’re extension methods. If such class grows too large for a single source file, C# has partial classes.

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

#167

Earlier quoted context omitted.

Interfaces are inheritance, just without code. But interfaces definitely serve at least one role of an abstract base class.

Maybe. But then even FP languages are considered OOP, as most of those languages have records and interfaces.

Yes I agree. Once you have interfaces with default implementations especially, you have non-nested OOP

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

#169

I think there are many useful ideas in OOP languages and I still struggle with purely functional languages, I think/hope we'll see increasingly mixed model languages. I'd be interested to see a language like C# but with: + Immutable by default. + 'Free' functions, so they don't have to be in classes. + No inheritance. + Some sort of distinction, and I'm not clear how it would work yet, between data objects (immutable…

Agree about immutability (I would love to have “readonly” to be applicable to classes), but I like the current static classes approach. It’s a single keyword, the language guarantee you won’t have any instance fields or methods in these classes. Global functions pollute namespaces, and auto-complete index. Static classes provide local namespaces for these functions, they also hide implementation details. I sometimes…

It's a good point about auto-complete I hadn't considered, maybe globals could have some obvious name thing going on, I hate this suggestion but for example an underscore prefix.

Some examples of where global functions might make sense, the Main function of a console application doesn't need to be in a class, or the general Utils and Helpers approach soon becomes cumbersome, you end up having to name things that don't really need names. While static classes can help organise these global functions you also end up playing the naming game when you don't need to. It might not be any improvement but it's an interesting thought exercise to imagine functions living in just a namespace, not a class.

I think in C# static still doesn't give you enough guarantees at either the class or member level. A static class can still have public static mutable members which is a horrible code smell. C# contains enough flexibility to do the things I want, e.g. make things static and readonly, but it's a lot of additional typing and I'd be interested in seeing the model reversed, e.g. immutable defaults with something like `public mutable class Foo` which I remember having seen in other places (F#?).

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

#170
post #162

Earlier quoted context omitted.

C++ is multi-paradigm. While people can write OOP code in C++, they can also write header-only libraries, which is generic programming. In C++ generic programming, inheritance is merely a language feature to get what you want, not the main method of abstraction.

You can do that in C, though. C++ was originally "C, with Classes", so OOP was the whole point of C++ existing in the first place.

> C++ was originally "C, with Classes", so OOP was the whole point of C++ existing in the first place

This is like describing a middle aged man based on what he did in middle school. Things evolve. C++ has. Almost to a fault where one can legitimately call it a mutation.

Post reply on HN