Live data from Hacker News

Moving Beyond the OOP Obsession

prog21.dadgum.com

31–40 of 72 posts

Re: Moving Beyond the OOP Obsession

#31
post #27
post #23

Earlier quoted context omitted.

A struct is an object. Even a plain integer is an object, considering the referred article was talking about C++. (Yes, you cannot inherit all kinds of objects – but you definitely can inherit any kind of struct, POD or not.)

Well, if everything is an object, I guess everything is an object. Usually when people are talking about OO objects they mean data+behaviour.

Object refers to a memory object, which could be data or text(functions).

Re: Moving Beyond the OOP Obsession

#32
No one technique scales on its own. Assembly, macro assembly, expressions, functions, classes, inheritance, templates, closures, data flow, and even message passing if you want performance.

Everyone keeps looking for the silver bullet, but ends up with answers that are simple, easy, and wrong.

If there is a bullet at all I think it is accepting that software architecture is made up of all these things + tools that give lots of extra information easily + interactivity and small iteration times.

I think when most people are being overwhelmed with complexity they want a silver bullet so badly they will believe that there is one against all evidence to the contrary.

Re: Moving Beyond the OOP Obsession

#33
post #3

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

> 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

#35

Another good article expressing a similar opinion which some might not have seen http://blog.codinghorror.com/your-code-oop-or-poo/

"Object Oriented Programming" in Portuguese is "Programação Orientada a Objetos". So for me the two categories are one and the same :P

Re: Moving Beyond the OOP Obsession

#36
post #6

What baffles me about OOP is that massive aspects of how to use it have changed, and that change happened after it gained popularity as a good technique. How could it have become popular when people were doing it wrong? The article mentions inheritance, but there's also heavy vs light classes. When I was taught OOP, an object knew how to do all the things to itself. It could draw itself on the screen, modify itself,…

Initially there was machine code (well, manual wiring of computers). Then there was assembly, and that worked. Then there were Fortran and Lisp and Algol, and somehow we still needed more languages and methodologies.

GOTO was fine, until it wasn't. Then we had structured programming and things were better.

Every language and methodology has had its pros and cons, and in general the trend has been towards "better" (by some dimension in a large, multi-dimensional space) languages and methods.

Heavy classes were an improvement over what existed before them, not because they were heavy classes, but because what was before them was still (often) unstructured code.

Light classes, moving things up a level so that, for instance, your graphical object doesn't draw itself, but instead knows enough to inform the drawing class how to draw it, is better in one particular regard: same object can be rendered in any system by updating the layer above it. So instead of updating 100 drawn objects, you now update 1 drawing object.

That doesn't make heavy classes "wrong", they were fine at their time (probably more performant, and almost certainly an improvement in some ways over what existed before them). But light classes with some degree of abstraction is often better (too much is still a problem, damn you ). Better, in this case: shorter code, fewer "moving" parts, easier to reason about, easier to manipulate. It is potentially less performant (depending on language and design choices), but that's not a guarantee.

Re: Moving Beyond the OOP Obsession

#37
post #2

I've encountered this code a lot in C, and every time I thought that this style of > stuff_do_something(stuff, some_parameter) _is_ OOP and identical to > stuff.do_something(some_parameter) , although in language without support for OOP (of course, you can hack OOP on top of C with preprocessors and stuff, but let's pretend we forgot about that embarrassing abominations). And every time I saw that I wished that I cou…

Exactly. OOP is: a) A code naming/organisational issue b) Some formalisation of structure, so that developers can specify what is/isn't allowed in their code. Both of thise have advantages and disadvantages, and the structure can be over-formalised and made too complex. But this doesn't make OOP bad. It makes bad design bad.

Well yes, when you redefine "OOP" to mean "well-organized code," then all well-organized code is object-oriented. That's not what people mean when they refer to OOP though -- they're talking about data+behavior encapsulation, inheritance, message-passing, etc.

Re: Moving Beyond the OOP Obsession

#38

I've been saying this for years. Historically, yes, OOP has its own roots. But for all effects and purposes, C++ with headers controlling visibility is the grandfather of OOP. If you got that, then you've got OOP basics. (And, as the author points out, 90% of what you'll ever need) There's another way of "going beyond OOP" that bears some thought, and that's growing a program by incrementally adding functions, then g…

This is how Node js development tends to be done.

Re: Moving Beyond the OOP Obsession

#39
post #33
post #3

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

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

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

#40
post #39
post #33

Earlier quoted context omitted.

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

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.

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.

Post reply on HN