Nuno Afonso
  • Home
  • Flux
  • About

Unity & Object-Oriented Programming

4/7/2018

3 Comments

 
There was a session in GDC called “A Data-Oriented Approach to Parallelizing Hierarchical Transforms (Presented by Unity Technologies)” and given that I had seen the past Unite the session by Joachim Ante on their new Entity Component System I wasn’t planning to go to it. I had never heard about Mike Acton, so when somebody mentioned to me "it should be really good" I decided to give it a shot.

The session starts very well; Mike makes an analogy on how Unity is like a car full of clowns, and before moving forward we have to make sure all those clowns are out of the car. At this point I’m pumped, I’m thinking that finally somebody is going to break out of this idyllic view that the Unity developers often portray (can’t remember how many discussions I was involved with Unity about weird decisions, like their IMGUI or how “C# is fast enough”) and put all its skeletons out in the open. And then he drops the bomb: “and the first clown we have to get out of there is Object-Oriented Programming”.

​Object-Oriented Programming is Communism and Data-Oriented Programming is Democracy

I’m always very weary when people take extreme positions. By default, Communism has a very good concept; to make society more equalitarian. As a goal this sounds pretty good to me, but even Marx predicted that for it to be achieved, the sacrifice would have to be huge.

At its core, Object-Oriented Programming (OOP) has the following principles:
  • Encapsulation
  • Abstraction
  • Inheritance
  • Polymorphism

These are very simple concepts. Nothing inherently wrong with them, and at its heart it is what OOP is. The problem, like with Communism, is not about the goal but what we do to try to achieve it.

In my opinion, there is a massive problem with how programmers are being taught today. In my line of work, I very often come across two major issues: over engineering, and suboptimal code.
​
Over engineering is the worst from architectural point of view, because it goes against the whole purpose of OOP; it makes things more convoluted, complicated, unmaintainable, inflexible.

Suboptimal (some might call it simply bad) code has to do more with how programmers code without realizing the implications that the code they are writing has, e.g. allocating memory like crazy, algorithms that iterate over data far more than needed.

I mostly blame schools because they teach students to do things “the right way”, but the students have their share of blame too. It is specially frustrating for me when young programmers are very stubborn in their “right ways” of doing things, and they should be more open to understand that “right” is a very subjective term (history teaches us that over and over), specially when sometimes these mentors that taught them never actually had real world experience on the subjects.

Not saying school or teachers are bad, but I do think it could be better. It’s weird to me that at the point people should be most open to learn (given that’s what they were doing for most of their life), they are the most closed to it.

And now here comes Data-Oriented Programming (DOP), the Democracy, allowing all developers to take hold of the full potential (of not only their games but themselves). Democracy is one of those interesting concepts, in theory everybody has an equal say in it and the majority drives the direction but, as we’re seeing these days, what happens when the majority is being fooled by huge propaganda machines?

This is how I feel about DOP; at the moment there’s this idea starting to push it forward as “the right way” of programming. If bad OOP code can be tricky as hell to get around with, one can only imagine with DOP code.

DOP was the old way of doing things (more out of necessity), that’s basically the core of C programming language, but at a certain point everybody (i.e. in general programming, not talking about low level kernel) kind of flocked at the idea of having a better way to organize things without sacrificing much performance.
​
Don’t get me wrong, I don’t think that DOP shouldn’t be used; like every tool it has its purpose but as a default I believe that OOP is a far better option when creating complex code like an App or Game, specially when you have a lot of people involved (exacerbated by lack of experience).

​The Biggest Clown

Unfortunately, it seems to me that the biggest clown in Unity will continue there. He’s the one with the driving license, and as such will not leave the car. I’m not talking about nested prefabs, input systems, core loop methods based on broadcasts, or any other piece of code; I believe that for Unity to become a real AAA engine, Unity Technologies needs to start making games.

Only when you have to do big games with a lot of people you realise all the problems that actually exist, and all of a sudden these cannot be skimmed over or ignored. They are show stoppers (or at the very least delayers) and require full on attention to tackle and solve them.

For long I’ve had a love/hate relationship with Unity. I’ve been there from the start in the Mac OS days, and I’ve been actually very close to dropping it, but fate brought me right in for professional reasons. It’s funny because Unity is in the best shape it has ever been, but like a victim of domestic abuse that endured for years eventually there’s that little thing that will tip the scales.
​
I honestly hope that Unity becomes better, but I advise extreme caution specially to inexperienced teams following extremist points of view.
3 Comments
Vonish
1/18/2019 08:54:51 am

Nice article. I absolutely adore when people get philosophical about programming. I’m getting a bit judgmental here, but I believe the coders most pleasurable to work with enjoy trying new things but also “use what works” when the time calls. The cliché “there is no silver bullet” always comes to mind when I think about software development, and life for that matter. It’s so tempting to go black and white on an architecture or strategy, but we have to remember it’s the journey, not the destination.

Another thing - we’re dealing with digital bits here (computer code) which can be arranged and re-arranged as many times as we like before being shipped. Just look at the animated movies Pixar makes: they go over every second of film frame by frame and decide if it sucks or not using the “Brain Trust” method which works for everyone (see the book “Creativity Inc.” by Ed Catmull) Why can’t we do the same thing with code reviews and showcases?

Anyway, thanks for the great article and thought provoker. Keep pondering!

Reply
M
4/20/2020 03:54:49 pm

Thanks for the article.
Though I'm a little disappointed how many people take offence at what appears to be the "anti-OOP" stance, particularly of Acton.

I'm admittedly not a massively experienced programmer, but I have been coding for around 24 years off and on.

I am sad to see so few people caring about the hardware.
We all want the easy fix; to be able to code these wonderful, abstract concepts as fast as possible (usually sadly because of a broken profit-driven mentality in society).
But the reality is we should care and be interested in the actual hardware.

I digress. I wanted to point out (I could be wrong) that Acton and a few others don't appear to me to blame OOP. It seems the issue is more that OOP is easily abused because coders tend to slip into a comfort zone, believing that computers actually understand the mental abstractions of a human brain, or the real world.

And beyond that, maybe you will get what you want from Unity.
Acton is a game industry veteran (I think that's a fair assessment), and is taking Unity likely in a very promising direction, along with some other hardcore programmers, nay, engineers.

But what do I know :) Time will tell.

Reply
Nuno Afonso
4/21/2020 01:57:07 am

Maybe it didn't come across well, but my point wasn't that OOP is better than DOP. My point was I think extremist POVs are always bad, and IMO Unity is following one.

If you check Unity development, they are pushing DOTs/ECS as the solution to all the problems in the world, and my point is that Unity has a lot of more problems they didn't fix / dismissed, things that are actually crucial to games releasing, and then you as a developer need to tackle them, quite some times in hacks / workarounds and huge time sinks (e.g. build pipelines, asset syncing).

Some of these things changed, but let me tell you that for 2 times I had visits from Unity developer relationship team, and we presented some problems and you wouldn't believe how we were dismissed, like they were minor issues. And we were a big studio, not a little indie studio.

ATM Unity is in this void, and I honestly can't tell where it will end up. Maybe in 2y, after all this DOTs reworking is done the engine will be amazing, maybe it will be a horrible mess. Maybe it will be the most performant commercial engine, but maybe also along the way it will use that easiness of use / workflow that was what made Unity standout.

I do hope that Acton's (and maybe others' less visible) experience will help control what comes out, but I also was there when they deprecated Raknet and brought in "industry veterans" to give Unity "The Network System", and now that system is being deprecated. Unfortunately when you're talking about giant development teams, either all your chain of command is really good, or it's really hard to change things for the better.

In any case, and although I haven't worked with Unity for 1.5y now, I really hope that it will pull through and be a very strong engine all around.

Reply



Leave a Reply.

    Author

    Nuno Afonso
    Game & Tools Developer

    Archives

    April 2015

    Categories

    All

    RSS Feed