Live data from Hacker News

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

news.ycombinator.com

201–210 of 234 posts

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

#201
post #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 exa…

W.r.t. dynamic scope, I agree that there are some nice use-cases for it. Racket has good support for dynamic scope (it calls dynamically scoped variables "parameters"), and I've found them to be useful, e.g. for handling environment variables of sub-processes.

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

#202
post #135
post #81

Earlier quoted context omitted.

When the goal is to model something “in real life” OOP tends to map decently well and it’s easy to teach. When you’re trying to make sure your program isn’t going to go off the rails, limits on mutation is one of the first places to look. When your software has 50mm+ valid states, one should hopes they have a large manual QA team. If you have all the possible states held in their own subsystem, you can automate stabi…

Why is modelling in OOP any more "real life" than with other programming paradigms? I've heard this many times from OOP zealots but I just don't get it. Most examples of this I've seen focus on physical objects such as cars which is just ludicrous as your average piece of software is morel likely to be dealing with a data structure, such as a user profile, than anything physical.

Game engines tend to model real life and they are usually very OOP.

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

#203
post #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 exa…

You have some good points. But have you tried Idris or Agda? My problem with OO is one of culture. If and only if you work with big codebases you start to feel that you can’t make assumptions about anything. For all I know the plus operator can send nukes. Then they say it doesn’t matter because they made the perfect lasagna with a million layers. I know there’s a million ways to code with oo to make it better. But I…

The Haskell community is full of terrible culture, things like badly designed libraries that assume the type signatures are the same thing as documentation, or ridiculous constructs designed to seem clever or work around the various straitjackets Haskell imposes.

If you feel you can just 'trust the assumptions' in Haskell but not in OO environments you've probably just been comparing very different codebases written by very different programmers.

In a codebase that uses OOP well it's very easy to understand what assumptions you can make and the tooling can be excellent. For instance, IntelliJ will happily show you all the possible implementations of a virtual method if you're using polymorphism. "It might launch the nukes" is pure Haskell meme noise - the equivalent unexpected behaviour for Haskell would be a difficult to understand space leak.

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

#204
post #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 exa…

> There's nothing wrong with object methods (that's 100% pure syntax vs. a function call) Not really; in OOP a method call like `foo.bar(baz)` sends the `foo` object the message `bar` with argument `baz` (in Kay's current terminology); or, in more 'mainstream' terminology, it looks for a method in the `bar` slot of `foo` and calls it with `baz`. As far as I'm aware, this is a pretty core concept in OOP: if our code i…

You can do that sort of thing in Kotlin, which is an OOP (well, multi-paradigm) language:

    inline fun  String.fromString(): T {
        return when {
            T::class == String::class -> this
            T::class == Int::class -> Integer.valueOf(this)
            else -> TODO()
        } as T
    }

    val str: String = "abc".decode()
    val int: Int = "123".decode()
You have to be careful with type inference: if there's no way for the compiler to figure out what type you want from the call site, you'll get an error.

You might say this isn't OOP in the strictest possible sense, but extension methods + type inference + reified types gives what you're asking for in a way that's natural for an OOP programmer.

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

#205

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…

Fragile base classes only affect C++. That's not inherent to OOP. Java solved it completely.

Inheritance gets ragged on a lot these days, but frankly I see it all the time in most mature, production codebases and it's usually used properly and in a tasteful manner. IMO the idea that inheritance is evil is just people who want to make a new programming language looking for a philosophical edge - just like how a bunch of language designers decided exceptions suck because "you can't see the control flow" (eg. in Go) and now years later have basically admitted their error handling sucks, so they need to add something very exception-like back in. Actually exceptions never sucked but Go's designers needed some sort of fresh idea to justify their project.

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

#206

Objects are not fundamental to computing. This is why there are no deep solutions to any of the standard downfalls of OOP.

A small but very insightful tidbit. I am not completely sure if I agree with you: At some point in my life I programmed in assembler (8086 and Z80), so I know very well how computing looks in its more reductionist way. They are JMPs, calls and JNZ, JZ, PUSH and POPs. However, the reason why we use say, structured programming, functional programming and OOP is because abstractions are always helpful for people. It mak…

Even that (1:1 mapping) is pretty far the OO Alan Kay intended. Even relations (AKA the foundation of many databases) are built out of rigorous math. I'm not aware of any such derivation for objects, other than "let's keep the methods with the data they act on." I'm sure I'm oversimplifying that, but I do reasonably fail to find something deeper.

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

#207

Earlier quoted context omitted.

> There's nothing wrong with object methods (that's 100% pure syntax vs. a function call) Not really; in OOP a method call like `foo.bar(baz)` sends the `foo` object the message `bar` with argument `baz` (in Kay's current terminology); or, in more 'mainstream' terminology, it looks for a method in the `bar` slot of `foo` and calls it with `baz`. As far as I'm aware, this is a pretty core concept in OOP: if our code i…

You can do that sort of thing in Kotlin, which is an OOP (well, multi-paradigm) language: inline fun String.fromString(): T { return when { T::class == String::class -> this T::class == Int::class -> Integer.valueOf(this) else -> TODO() } as T } val str: String = "abc".decode() val int: Int = "123".decode() You have to be careful with type inference: if there's no way for the compiler to figure out what type you want…

> You have to be careful with type inference: if there's no way for the compiler to figure out what type you want from the call site, you'll get an error.

I'd say that's a feature, not a bug :)

> You might say this isn't OOP in the strictest possible sense

I would say it's not OOP in any sense. Having one function implement all the different behaviours, and pick which one to run by switching on some data (in this case the class tag) is a classic example of being not OOP.

As a bonus, this ignores dynamic dispatch (the only implementation is for `String`) and it's not polymorphic (the same code doesn't work for different types; instead we have different clauses for each type).

This would be salvagable if `String::fromString` only enforced the type constraint, and dispatched to `T::fromString` to do the actual parsing, e.g.

    inline fun  String.fromString(): T {
        return when {
            T::class == String::class -> this
            else                      -> T::fromString(this)
        } as T
    }
I'm not sure whether that would work or not (I've never written Kotlin), but I still think it's "messy" (monkey-patching methods on to classes, reimplementing dynamic dispatch manually, inspecting classes (via the equality check), going out of our way to prevent infinite loops, etc.)

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

#208
post #135
post #81

Earlier quoted context omitted.

When the goal is to model something “in real life” OOP tends to map decently well and it’s easy to teach. When you’re trying to make sure your program isn’t going to go off the rails, limits on mutation is one of the first places to look. When your software has 50mm+ valid states, one should hopes they have a large manual QA team. If you have all the possible states held in their own subsystem, you can automate stabi…

Why is modelling in OOP any more "real life" than with other programming paradigms? I've heard this many times from OOP zealots but I just don't get it. Most examples of this I've seen focus on physical objects such as cars which is just ludicrous as your average piece of software is morel likely to be dealing with a data structure, such as a user profile, than anything physical.

My favorite example is SimCity. Any time you have a bunch of models that operate mostly independently and somewhat based on neighbors OOP seems to map nicely. When you are taking more abstract concepts or data flows (which is... probably 95% of web programming and 80% of all programming for example) it doesn't map well, and you end up with a lot of natural funkiness because the base modeling language doesn't match the concepts.

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

#209
post #182

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 fun…

> They eliminate inheritance, replacing it with interfaces. Exposing the objects for what they really are, structs with functions attached, makes this strategy easier. I don't see how this is not already achievable in Java or C#. No one is forcing you to use inheritance. And when you really need it, it's there for you to use instead of jumping through hoops.

That's basically true. Languages that use interfaces with structural typing are significantly easier to work with though. You can "implement" an interface implicitly by just having matching fields

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

#210
I co-authored the somewhat-famous Games Pack 1 for the TRS-80. I grew up with 8080 and Z-80 programming for low-level and my first high-level languages were APL, BASIC, Pascal and Modula 2. All top-down modular. Then I designed a language called R-code, for robot control, and another language called LIM (Limited Instruction Model). It was clean, simple, readable, and easy to understand. I say use what you enjoy and don't worry about trendy things like OOP. All good wishes.
Post reply on HN