News for hackers. Stuff that matters.
Re:Moving Beyond the OOP Obsession by sparkie on Monday March 28, 2016 @06:43AM (#11373534)
I don't disagree with the author's sentiment about inheritance (or OOP in general), being used and taught wrongly, but I still think it's a necessary tool to have available.

Without inheritance, as soon as you want to cast mixer to something else, you're either relying on binary wizardry by the compiler (reinterpret_cast. ie, undefined behaviour), or you need to break encapsulation to copy the fields over from one object to another.

Of course we could use an opaque pointer to our objects instead, but if your solution is to cast anything to (void*), where could that possibly go wrong?

OOP inheritance is pretty much doing that, but in a constrained, statically enforced way, which prevents programmers from making elementary mistakes or trying to make assumptions about the way hardware works.

Of course, the last example of the singleton works, but it also doesn't help to explain why we might use singletons in OOP. If we assume we have both a hardware mixer and a soft mixer which both have the set volume method, we wan't polymorphism so we can treat them equally. In the author's solution, we must treat each specially at the call site, which also violates our open/closed principle - we want to add new mixers without hacking (and breaking) the existing code.

Still, I pretty much agree that we should rethink the way these are taught. Perhaps every student should write his own OOP language before being let loose with it.

Re:Moving Beyond the OOP Obsession by l_dopa on Monday March 28, 2016 @07:48AM (#11373701)
You're describing subtyping which, like modularity, does not require inheritance or really any other part of "OOP".

I think that supports the article's point that C++, Java, etc. only support certain language features in an ad-hoc way tied to their object systems, making them, among other things, poor teaching languages.

Re:Moving Beyond the OOP Obsession by rlidwka on Monday March 28, 2016 @10:19AM (#11374359)
> Without inheritance, as soon as you want to cast mixer to something else, you're either relying on binary wizardry by the compiler

Why would you want to cast mixer to something else? What real-life task does it solve?

> If we assume we have both a hardware mixer and a soft mixer which both have the set volume method, we wan't polymorphism so we can treat them equally.

Polymorphism isn't OOP feature. You can have overloaded `mixer_set(struct, int)` without any OOP wizardry involved.

Re:Moving Beyond the OOP Obsession by scomment on Monday March 28, 2016 @11:39AM (#11374885)
> Why would you want to cast mixer to something else?

Did you ever heard about interfaces? You can have a IMixer interface, a Mixer baseclass and some concrete mixer classes depending on your task. Like null-mixer for mocking, software mixer for legacy computers, hardware mixer with GPU support, etc. Use your imagination, Luke!

Re:Moving Beyond the OOP Obsession by chipsy on Monday March 28, 2016 @12:53PM (#11375452)
Or you could just have data. The behavior of mixing is not going to change because of those things.
Re:Moving Beyond the OOP Obsession by Retric on Monday March 28, 2016 @10:50AM (#11374564)
Let's suppose you want labels, text boxes, and buttons on a form.

Now you can do this without OOP or making a huge chunk of form code, but OOP is a natural fit. Especially if we may want to add pictures or video in the future.

Re:Moving Beyond the OOP Obsession by seivan on Monday March 28, 2016 @11:02AM (#11374639)
Are you saying all these outlets (labels, text box, buttons) are inheriting from a base FormObject that can be rendered?

That would work without OOP. Make a FormRender component that manages that logic (being rendered in a form) and other components, one that manages a keyboard, other that can be clicked and handle hover, touch states, etc.

Re:Moving Beyond the OOP Obsession by Retric on Monday March 28, 2016 @11:32AM (#11374841)
Sure, but routing get's complex in your solution. The point was OOP is a natural fit for collections of different types in some context ex:GUI, Simulation, etc. The classic OOP case is probably a MUD where OO code ends up being very straightforward.

IMO, the problem is it works really well in so many contexts that people end up trying to use it everywhere.

Re:Moving Beyond the OOP Obsession by Jtsummers on Monday March 28, 2016 @12:04PM (#11375053)
OO in MUDs seemed so natural to me, I think, because they're closer to the actor model that OO was really designed for. Instead of "methods", many objects in MUDs (depending on the system, I used to know more when I was research writing a MUD engine in erlang), respond to messages in more of a smalltalk-style.
Re:Moving Beyond the OOP Obsession by seivan on Monday March 28, 2016 @02:43PM (#11376322)
Routing? I'm just saying that OOP is as much of a perfect fit to GUI that Entity Component Systems (composition) are.
Re:Moving Beyond the OOP Obsession by Retric on Monday March 28, 2016 @03:24PM (#11376647)
ECS works well when you can predefine everything ahead of time. But, it must be extended for every additional type.

As to messaging, consider what happens when you add JavaScript that can change the DOM. Now, you need to pass messages in both directions not just What is your Height- Width, but also my Height-Width has changed. Animated Gifs or Videos now want to update things in real time, and other windows can cover parts of your view port.

And let's not forget about transparency.

PS: ECS can still work, but it starts getting really complex.

Re:Moving Beyond the OOP Obsession by scomment on Monday March 28, 2016 @11:41AM (#11374901)
And you started slow reinvention of OOP!
Re:Moving Beyond the OOP Obsession by seivan on Monday March 28, 2016 @02:42PM (#11376313)
No, the name of the game is composition. See ECS in game dev.