News for hackers. Stuff that matters.
Re:Three Big Lies (2008) by devishard on Wednesday July 06, 2016 @05:23PM (#12045985)
I totally disagree that #2 is a lie. Code should be designed around a model of some part of the world, it's just that what the author is describing is a pretty bad way of modeling the world.

Take this part: "If there's a rocket in the game, rest assured that there is a "Rocket" class (Assuming the code is C++) which contains data for exactly one rocket and does rockety stuff. With no regard at all for what data tranformation is really being done, or for the layout of the data. Or for that matter, without the basic understanding that where there's one thing, there's probably more than one."

This is an enormous straw man. You don't need to be using C++, or even a real OO language, to design your code around a model of the world. I'd go so far as to say that C++ is a pretty poor choice of language for modeling the real world. And even in an OO language, no decent practitioner writes one-class-per-object. That's not how objects are intended to work, and even pretty bad practitioners of OO don't usually screw it up that badly.

And the underlying thing here is that if you model interactions in the real world accurately, at least the parts that are relevant to what you're trying to do, the data transformations and layout tend to fall into place naturally. Of course there are exceptions; we don't have leak-free abstractions yet.

Re:Three Big Lies (2008) by jstimpfle on Wednesday July 06, 2016 @06:06PM (#12046185)
> And even in an OO language, no decent practitioner writes one-class-per-object.

But that's the stereotypical example of OO design. You have duck->paint(), duck->quack(), duck->plunge() all in one class (file) and of course the dependency mess and the scattering of aspects throughout the project.

These have definitely been problems in my own software design attempts and in many of the projects I've seen.

And even if you make more classes, so that your design is more like one class per concept/aspect, I think the criticism of Mr. Acton is: if you have many instances of a given class, then there must be a better way than calling a method on each individual instance.

In other words, the idea is that classes are fine (they promote modularization), but there shouldn't be more than one instance of each class.

Can't see a straw man there.

Re:Three Big Lies (2008) by devishard on Thursday July 07, 2016 @09:56AM (#12049320)
>> > And even in an OO language, no decent practitioner writes one-class-per-object.

> But that's the stereotypical example of OO design. You have duck->paint(), duck->quack(), duck->plunge() all in one class (file) and of course the dependency mess and the scattering of aspects throughout the project.

So much nonsense here. One class per object is absolutely not the stereotypical example of OO design. class != file. And dependency management is usually a problem because junior devs pull in a billion half-baked libraries to solve a problem--it's not an inherent problem with OO and it's certainly not a problem with trying to model the real world.

I'm not even particularly in love with OO. I particularly think that functional paradigms often do a better job of modeling the real world. What I'm really disagreeing with is the claim that modeling the real world is a bad practice.

> And even if you make more classes, so that your design is more like one class per concept/aspect, I think the criticism of Mr. Acton is: if you have many instances of a given class, then there must be a better way than calling a method on each individual instance.

If that was Acton's criticism, then he should have said that instead of saying that "code should be designed around a model of the world" is a lie. Particularly since if you're acting on a large list of objects, then representing it as if you're going through and then each object is acting is a pretty bad representation of reality.

> In other words, the idea is that classes are fine (they promote modularization), but there shouldn't be more than one instance of each class.

Now you're just confused. Acton specifically was criticizing one instance per class in the section I quoted, and now you're saying that's what he's supporting?

And for the record, if there's only one instance of your class, you didn't need a class.

Re:Three Big Lies (2008) by jstimpfle on Thursday July 07, 2016 @12:18PM (#12050269)
No need to get personal.

> So much nonsense here. One class per object is absolutely not the stereotypical example of OO design.

I didn't say that. I said: The stereotypical example is "one class per (concept / class of) real world thing(s)". Like "Rocket" or "Duck".

> If that was Acton's criticism, then he should have said that instead of saying that "code should be designed around a model of the world" is a lie.

It needs just a little context or reading between the lines to understand the intentions instead of twisting words to make accusations.

> Now you're just confused. Acton specifically was criticizing one instance per class in the section I quoted, and now you're saying that's what he's supporting?

I am not confused. He wasn't criticizing "one runtime instance per class", but "one per runtime instance per real world thing". That's something different.

The quote reads rest assured that there is a "Rocket" class which contains data for exactly one rocket. I translate, he suggests to combine all "real world rockets" in a single runtime object instead of representing each rocket in its own runtime object.

Concretely, he would make a "Rockets" class instead of a "Rocket" class, because that typically allows for simpler and more efficient implementation. (Of course, if there were also planes or missiles or bullets, he would think twice before making a Rockets class).

As I commented elsewhere on this page, there are very close analogies to relational databases -- especially the column-store flavour.

Re:Three Big Lies (2008) by devishard on Thursday July 07, 2016 @12:58PM (#12050571)
Okay, given your understanding of what he said, I can see why you might agree with him (although I don't), but critically, that's not what he said.
Re:Three Big Lies (2008) by dottrap on Thursday July 07, 2016 @08:13PM (#12052883)
Mike has given multiple talks on Data Oriented Design.

Another example he gave at CppCon was a Chair class. In a real game, you may have a static chair, a dynamic lighting chair, a breakable chair, a physics chair. There is a tendency to make these all relate through some common Chair class because they all share some "chairness" in the real world. But in reality, the data and transformations each need have nothing in common and trying to shoehorn them into some relationship because it resembles something in the real world is counterproductive.

Re:Three Big Lies (2008) by Ace17 on Thursday July 07, 2016 @01:41AM (#12047642)
What we call the "real world" already is a model ... and a simplistic one.

Lots of classes don't have a "real world" equivalent (linked lists, allocators, renderers, finite-state machines, functors, observers, octrees, parsers/loaders...). The "real world" will mostly give you incentive to abuse inheritance, while missing what the interfaces and abstractions are.

My argument isn't related to performance.

I don't have a problem with having a "Rocket" class ; however, if this class is responsible for everything "Rockety" (audio rendering, video rendering, serialization, target following, collision detection, ...), then it's gathering lots of dependencies at one single point, making the class painfull to reuse, and more generally painfull to depend upon.

I've seen this, and it's a design nightmare. Were you going to reuse this "Rocket" class in another application anyway? Does the rest of your application sees rockets as instances of "Rocket" classes?

Re:Three Big Lies (2008) by devishard on Thursday July 07, 2016 @09:37AM (#12049195)
> Lots of classes don't have a "real world" equivalent (linked lists, allocators, renderers, finite-state machines, functors, observers, octrees, parsers/loaders...). The "real world" will mostly give you incentive to abuse inheritance, while missing what the interfaces and abstractions are.

This is a pretty myopic view of what exists in the real world. Lists absolutely exist in the real world: a shopping list, a to-do list, a list of messages received. Lists are such a common data structure because they frequently provide a good model of things in the real world, in this case, a way that humans organize sequential items, tasks, or messages.

As for your other examples, sure, some of them are pretty poor pretty poor representations of what exists. And that's a great argument for why you should find a better abstraction. My argument from square one was that you should be modeling your things off the real world.

> everything "Rockety" (audio rendering, video rendering, serialization, target following, collision detection, ...)

Really? In what world do you live where Rockets render audio?

Again, this is just a straw man. What you're describing isn't even attempting to model reality, so you can't use it as a basis for arguing against modeling reality.

Re:Three Big Lies (2008) by jstimpfle on Thursday July 07, 2016 @12:36PM (#12050417)
As I already said, your tone is annoying.

Your parent's arguments are very clearly presented (and perfectly sensible); there is no need to twist words to "prove" him wrong.

>> everything "Rockety" (audio rendering, video rendering, serialization, target following, collision detection, ...)

> Really? In what world do you live where Rockets render audio?

Please, stop putting words into others' mouths. Actually what you do is my understanding of straw mans.

Re:Three Big Lies (2008) by devishard on Thursday July 07, 2016 @12:59PM (#12050585)
I'm not saying that he said rockets render audio, I'm saying that has nothing to do with modeling the real world. If you're criticizing the idea of modeling the real world, we should talk about actual models of the real world.
Re:Three Big Lies (2008) by jstimpfle on Thursday July 07, 2016 @01:09PM (#12050677)
We agree it's not a good way. But it's how the stereotypical OOP project will implement it.

The other way I'm familiar with is implementing rocket audio rendering at a central location (where also sheep and houses audio rendering is implemented).

That's the data oriented way. But the "drawback" is that one then needs access to the "raw" rocket data (one could still do it with a Rocket class, but would have to make a very complicated data-getter interface). Not very OO.

Thanks for your friendly reaction to my criticism, by the way.

Re:Three Big Lies (2008) by Ace17 on Thursday July 07, 2016 @01:21PM (#12050751)
(Please note that I was specifically talking about "linked" lists: when we use them, their "linked" part rarely matches something in the real-world)

OK, let's go for more examples of well-used classes not representing real-world things: a solver, an interpreter, a compiler, an AST, an arithmetic expression, a grammar, a saved game, a DSP filter, a target architecture, a process, a thread, an AI script, ...

My "Rocket" example isn't a strawman, it's a counter-example. You can ignore the audio rendering part if you don't find it plausible.

Re:Three Big Lies (2008) by Ace17 on Thursday July 07, 2016 @12:46PM (#12050476)
> Really? In what world do you live where Rockets render audio?

a shooter video game using procedural generation / sound synthesis?

Re:Three Big Lies (2008) by devishard on Thursday July 07, 2016 @01:02PM (#12050603)
That's not "modeling the world", or if it is, it's a very bad model of the real world. Rockets don't render audio.
Re:Three Big Lies (2008) by Ace17 on Friday July 08, 2016 @01:20AM (#12053669)
Rockets do make their own rocket noise, don't they? (if you prefer, we can call this "sound synthesis" instead of "audio rendering"). My point is that this code probably shouldn't be in the same class than, for example, the "target following" code. It would be an obvious violation the single responsibility principle (SRP).

Actually, I've seen lots of SRP violations caused by blindly "modelling the real world" (shape drawing functions inside the "Picture" class, inverted inheritance hierarchies, focusing on implementation reuse instead of focusing on interfaces, Square class derived from Rectangle class, ...). This alone is not a good enough design guide, and is sometimes counterproductive.

Have a look at how game developers struggle with deep class hierarchies. Many of them are moving, for the better, to Entity/Component based designs. This is a step back from "real-world modelling" (since you don't need/have a "Rocket" class anymore).