PDA

View Full Version : Why use objects?



blackvoid
12-09-2006, 08:34 PM
I am not a big expert on objects, but they really seem to make debugging very hard and complicated. Also you can have a lot of nasty memory leaks. I am a coder for a complex game engine and simple arrays are easy to use and cause much less trouble. On top of this, they make code harder to read and less easy to understand.

Objects of course make sense if you want reusable, standalone components, but if it is just for yourself, you can simply cut and paste code. Yes, it could be a bit more work, but you avoid tons of problems that can happen to objects.

Any thoughts?

czar
12-09-2006, 08:56 PM
In fact the opposite is true. Using objects makes your code easier to manage, easier to read and easier to add to and fix.

I don't see how using objects creates more memory leaks - if you stick to rules of creating and freeing then their is no problem. Great thing in my mind at least is that you can make really complicated objects that interact with the rest of your program/game without making the code harder to read and follow.

Robert Kosek
12-09-2006, 09:37 PM
Objects allow for modular dependency, and a level of versatility you cannot achieve in records. For example I could have a simple particle definition within my game with a few special case child objects. We'll call 'em:

TParticle
TTimelineParticle class(TParticle)
TFaderParticle class(TTimelineParticle)

Rather than go into details I'll keep it high level and abstract. You could use specific definitions within the 2nd class to provide specific or scriptable points in the particle's lifetime, changes to anything it has or does, while the 3rd class could provide a specific fade one image out and another in. Doesn't really matter how or what you do with it, but the framework is simpler than that of a huge record with data variables for every possible particle setting. Not to mention smaller and more compact. :)

You must adhere to strict creation and destruction protocalls to avoid memory leaks, yes, but this is very easy and not obstructive in any way. It makes debugging no less or more difficult though, as you can trace problems etc to their source, plus you can manipulate the object(s) without affecting any other game code.

cragwolf
16-09-2006, 04:10 AM
There's a time and place for everything, even objects. But I would urge everyone to take a look at other programming paradigms (e.g. functional and generic), too. Learning is fun.

Chebmaster
17-09-2006, 08:44 AM
Objects can be derived from the previously created objects, adding a new functionality or replacing the old one (thanks to virtual methods). Objects are a great mechanism and a must-do for any higher-level game structures. Although I don't think that using them for particles is advisable. Same for vertexes in a model and other low-level stuff.