News for hackers. Stuff that matters.
Re:Why is OOP still so widely spread? by didibus on Thursday September 03, 2020 @01:33AM (#24361038)
> I think it's lazy to dismiss the OOP as hate from experts who are complaining

I'm sorry if this is what you understood. The hate is from people hearing the complaints of experts. The experts generally have great understanding of the pros and cons, and are aware of the weaknesses, which they will openly talk about and sometimes that will make it sound worse, almost hyperbolic to others. Even I'm faulty of doing this, I might say this just sucks, or it's total rubbish, but really I mean it's pretty good and there's a lot of good ideas and parts, just needs some refinement and a few modifications because there are still problems with it, and I just faced one such wart so I'm frustrated and writing a big blog post to complain about it.

And this is the source of the misunderstanding. Overreaction and hyperboles from experts, taken at face value to those who are learning about it.

To your other points, I think it's interesting you bring up React since its biggest competitors: Vue, Svelte and Angular are all OO based and seem to be doing well.

> Can you name a contemporary expert or a platform that started or spent a good chunk of time as FP and ran back towards OOP

Hum, I think most did. OCaml added an object system to ML. CommonLisp added an object system to lisp. Haskell added TypeClasses. Scala is an attempt at an Haskell like language with a full object system. F# and Kotlin both have object systems as well. One could argue actors are a purer form of OO. And so on.

See, my point is that experts only ever complained about certain aspects of current iteration of so called OO programming languages. And as you can see, alternate languages they'd reach for or newer languages after them (or even newer version of those languages) all tried to address those shortcomings, but did not throw the baby out with the bathwater. There is convergence of ideas, and most of those languages have many if not most of the OO staple feature set, while having taken a few out or added some other inspired often by FP, but sometimes by other paradigms too.

Re:Why is OOP still so widely spread? by bryal on Thursday September 03, 2020 @06:41AM (#24362657)
> OCaml added an object system to ML. CommonLisp added an object system to lisp. Haskell added TypeClasses. Scala is an attempt at an Haskell like language with a full object system. F# and Kotlin both have object systems as well. One could argue actors are a purer form of OO. And so on.

Haskell type classes have nothing to do with OOP in the least, and as far as I know, Ocaml is a counterexample rather than an example to your point: they included OOP becsuse it was all the hype at the time of conception, but the OOP features are really quite unpopular today.

As you were completely off with Haskell, I can't exactly trust that you're right about any of the other languages "running back to OOP". If anything it seems to me the languages that started out as multi-paradigm FP/OOP have become more purely FP over time, as OOP has failed to prove its worth.

Re:Why is OOP still so widely spread? by pjmlp on Friday September 04, 2020 @02:57AM (#24372425)
> Haskell type classes have nothing to do with OOP in the least, and as far as I know

They surely do, OOP like FP, is very fuzzy and since the Simula/Smalltalk days there have been multiple ways to try to represent OOP concepts.

There isn't any OOP language that implements every OOP idea, just like there isn't any FP language that implements every FP idea.

Type classes allow for polymorphism, and combined with modules one can make use of module private implementations for the encapsulation part.

Extensibility can be achieved either by having a type implement multiple type classes, COM v1..vn style, or by delegation.

Re:Why is OOP still so widely spread? by bryal on Friday September 04, 2020 @08:19PM (#24380291)
Depending on your definition of the term, OOP can imply parametric & ad hoc polymorphism. Sure. But that in no way implies that all languages with that kind of polymorphism are OOP. That's gotta be, like, the first logical fallacy one learns about...

By your logic: 1. Ducks have feathers 2. All birds have feathers 3. Therefore, all birds are ducks

In any case, Haskell didn't get its polymorphism from any OOP language, so the point is moot. ML was first to introduce parametric polymorphism in 1975 — Java/C#/etc with their "generics" came later. Even ad hoc polymorphism with type classes was proposed 7 whole years (1988) before Java was even released (1995). And sure, the paper mentions that OOP has to solve similar issues, but "solving the same problem" ≠ "being the same solution".

Re:Why is OOP still so widely spread? by tome on Friday September 04, 2020 @04:23AM (#24372898)
> > Haskell type classes have nothing to do with OOP in the least, and as far as I know

> They surely do

That misses the point. The original challenge was

> > Can you name a contemporary expert or a platform that started or spent a good chunk of time as FP and ran back towards OOP

and didibus offered

> Hum, I think most did ... Haskell added TypeClasses

But that's simply not true that Haskell added type classes as an attempt to run back to OOP.

Re:Why is OOP still so widely spread? by pjmlp on Friday September 04, 2020 @05:47AM (#24373405)
Well all the FP languages without any kind of OOP like features, are doomed to stay as academia research projects, so.
Re:Why is OOP still so widely spread? by tome on Friday September 04, 2020 @06:26AM (#24373628)
Yes, if you define OOP-like broadly enough, that is surely true.
Re:Why is OOP still so widely spread? by didibus on Friday September 04, 2020 @01:48PM (#24377215)
That's my point. We should discuss the specifics and stop generalizing.

For example, OO has polymorphism as a core idea. TypeClasses are an implementation of ad-hoc polymorphism. This concept is a core part of OOP as well as all practical FP languages.

Now if we talk about OOP being bad, and we start talking about ad-hoc polymorphism. That's actually a great concept. It's one of the best concepts to appear in programming languages. So here we are talking about something great which most OOP languages have and make a core part of their offering. Something which Haskell also has and makes a core part of its offering.

Now you can try to move the goalpost, say nah, OOP doesn't mean ad-hoc polymorphism... okay what does it mean then? And maybe you mention class inheritance. Okay, is that it? What about abstraction, data encapsulation, overloading, access scopes, data instantiation, polymorphism, message passing, information hiding, actor-concurency, user defined types, etc. ?

So if you meant to say that inheritance is bad, then say that inheritance is bad. But even here, TypeClasses support inheritance?

> Haskell also supports a notion of class extension. For example, we may wish to define a class Ord which inherits all of the operations in Eq. [...] Note the context in the class declaration. We say that Eq is a superclass of Ord (conversely, Ord is a subclass of Eq), and any type which is an instance of Ord must also be an instance of Eq.

From: https://www.haskell.org/tutorial/classes.html

So what now? Maybe we actually mean that field inheritance is bad? Or what is it? And that's the kind of technicalities we should be discussing, not just say OOP bad, FP good.

Re:Why is OOP still so widely spread? by tome on Friday September 04, 2020 @04:02PM (#24378396)
Subclass polymorphism in typical OO languages (Java, C++, Python) is nothing like type class polymorphism. Class inheritance is nothing like type class sub/superclassing.

It's quite possible for one to be good and the other to be bad (and I would claim that is indeed the case).

Re:Why is OOP still so widely spread? by didibus on Friday September 04, 2020 @04:53PM (#24378780)
I'm talking about ad-hoc polymorphism, for example, in Java it would be interfaces and interface inheritance.

I believe in OO this concept comes from Self from 1987, where they first implemented Traits. In Standard ML TypeClasses were introduced in 1988 I believe. So it actually seems that OO would have had a form of ad-hoc polymorphism before ML. Now I don't want to debate where the ideas came from, I'm trying to say the "camps" are stereotyping which shouldn't be brought up in a technical conversation. Traits and TypeClasses share the same fundamental idea and purpose, and Haskell TypeClasses is its own variant of that idea, which is slightly different to Standard ML TypeClasses as well, and to how other FP languages do ad-hoc polymorphism, and in OO languages there are many variant on that idea as well.

Re:Why is OOP still so widely spread? by tome on Saturday September 05, 2020 @05:17AM (#24382407)
If you define "OO" to mean "has any form of ad hoc polymorphism" then I agree that Haskell is an OO language. On the other hand, I suspect most of the profession would assume that the polymorphism requirements in the definition of OO extend only so far as what Java, C++ and Python provide, that is, subclass-based polymorphism implemented using a vtable reference per object (or equivalent). The Haskell community certainly does not consider type classes to be a feature that provides "OO".

When I enter these debates I assume we're talking about OO in the de facto sense described above. Under that nomenclature I agree that ad hoc polymorphism is a useful language feature but believe that the OO implementation of it is bad.

Re:Why is OOP still so widely spread? by didibus on Saturday September 05, 2020 @03:42PM (#24386354)
This confusion of "what is meant by OO" is what my original comment was about.

The "hate" of OO is a misunderstanding, because most people are confused about what everyone and anyone even means when they talk about it, and that's also true of FP by the way.

So when someone criticizes OO for example, but their criticism is directed towards the fact that in Java, I cannot add methods to the existing HashMap class if I wanted too, and that annoys me. So am I criticizing OO? I'll probably label my article "Why OO doesn't work" or something like that. When I should have probably titled it: "Why it is a problem for Java classes to not be extendable from outside their class". Or at the very least: "Why subtyping for extension isn't always the most convenient mechanism for extension."

I see this happening not just on the topic of OO, but everywhere, and I find in a technical setting this is a dangerous thing to do.

I don't really know how to call this effect. I guess stereotyping is a good word for it.

Re:Why is OOP still so widely spread? by pjmlp on Friday September 04, 2020 @04:43PM (#24378697)
And then there is prototype polymorphism (SELF, JavaScript), pattern based polymorphism (BETA), component based polymorphism (COM, SOM, UWP), protocol based polymorphism (Objective-C, Swift, Smalltalk), ....

That is the thing, there isn't one OOP.

Re:Why is OOP still so widely spread? by andrekandre on Saturday September 05, 2020 @07:04AM (#24382737)
how does smalltalk use protocols? is it more ad-hoc like "responds to selector" or something else?
Re:Why is OOP still so widely spread? by pjmlp on Saturday September 05, 2020 @08:04AM (#24382975)
That is one way, informal use of categories, if we limit ourselves to Smalltalk-80 and Squeak.

Pharo also offers traits, not sure if Cinacom and Dolphin also do it.

Re:Why is OOP still so widely spread? by andrekandre on Saturday September 05, 2020 @03:46PM (#24386379)
forgot about pharo, yes it has traits (protocols)
Re:Why is OOP still so widely spread? by pjmlp on Friday September 04, 2020 @06:39AM (#24373710)
Just as broadly as FP can be defined.
Re:Why is OOP still so widely spread? by didibus on Thursday September 03, 2020 @02:39PM (#24367248)
It is hard to trace back the timeline history of all these things, especially as programming languages and their associated paradigms didn't evolve in a vacuum.

With that said, I would say some people would agree that operator overloading and ad-hoc polymorphism are core features of OO languages. In fact, many people learn first about ad-hoc polymorphism through an OO language, such as learning about Java Interfaces or Traits in Ruby.

So in that sense, TypeClasses do relate to OO.

This is where things get muddy. What is OO, what is FP? If you keep yourself stuck in the taxonomy you'll never leave it, because choosing labels is a subjective process. You can put the boundary wherever you want, there is no success criteria.

That said, there are real concentre ideas and implementation strategies. Those are more interesting, but don't get talked about very often.

Some of OOs main features:

- Data encapsulation

- Polymorphism

- Behavior abstraction

And Haskell similarly puts a lot of emphasis on those same features.

So what does one mean if they say OOP is bad? That those features are bad? That would transitively imply that Haskell similarly emphasises bad features?

Now I don't know about everyone, but that's not what I mean if I criticize OOP, I'm not claiming to avoid polymorphism, to get rid of behavior abstraction, and to stop trying to encapsulate data.

So the question is, what's wrong with OOP then? And this is where you'll see that things get nuanced and detailed oriented. And that it's not everything that is wrong, only certain specific things are not ideal and might have better solutions.

And at that point, you can't even speak of OOP generally, you need to speak of specific languages. For example, you could argue that Haskell TypeClasses are a better way to implement ad-hoc polymorphism than Java Interfaces. But someone could say that Self's Traits are just as good if not better than both of those approaches. Etc.

Re:Why is OOP still so widely spread? by johnisgood on Thursday September 03, 2020 @05:28AM (#24362287)
I like OCaml's and Common Lisp's OOP. I hate Java's OOP.
Re:Why is OOP still so widely spread? by didibus on Thursday September 03, 2020 @02:54PM (#24367410)
Yup, and what happens when you take one entity that has qualities you dislike and generalize it to all entities of the same color?

You get people hearing that OOP sucks, and they start to have fears and hatred towards it, thinking that all OO and every single idea and concept related to it is bad.

This is called stereotyping, and it's not productive to bring into a technical conversation. Even inside FP it exists, ever saw a Scheme programer and a Haskell programmer debate? They'd go on forever about whose the one true Functional Programmer.