I really dislike how people use objects! I’m taking a computer graphics class, and I’m having to do the homework in the rendering framework that they’ve created. Objects are used throughout the framework.
An object can be a very useful thing. But they abuse it to heck. The software itself is called “Application4”, which is an object. Then there are a bunch of member variables of the object Application4. These member variables behave like global variables for the rest of the software.
A function is a beautiful thing. It specifies explicitly what the inputs and the outputs are, and this is incredibly useful information when coding. But this gets destroyed when using objects. Now, all of a sudden, every member variable of the object is implicitly input into the function and available for its use; moreover, every function the member function calls has access to all the member variables of the object. This level of ambiguity makes it difficult to contain information; I have no idea what variables an object affects; it can almost affect anything.
On top of that, any semblance of order get eliminated. There’s another object called ForwardRenderer in the framework. And the code in there gets used somewhere. But lord knows where. The only way of knowing where this object gets instantiated is by tracing through all the code, or doing a file search (with grep or something). It’s very unclear where this object lives in the framework or how it gets used.
Finally, the TAs are enamored with objects, and they like showing how smart they are by using all the latest features in C++. There’s something called C++ 11 that has all sorts of objects that are subtle differences from what already existed. Examples include: unique_ptr, auto, shared_ptr, and unordered_map. The complexity is compounded when polymorphism is involved, and you can have virtual functions and static functions.
Finally, because of the complication of all of this, there are now “Design Patterns”, which are objects with more specific properties that are used to try and improve upon all the ambiguity that I just mentioned. So what are some design patterns? Factory, Multitution, Semaphore, Object Pool, Singleton, Builder.
I imagine that there are very legitimate uses of all of this stuff, where life gets much more complicated without it, and becomes much easier with it. It’s difficult to imagine, though, that this is the most elegant solution for almost all problems.
I have recently begun creating an image (and volume) processing library. I’ve decided to code it in C (rather than in C++). C allows structures, so I’ve created a struct that is image; it contains a pointer (a regular pointer, not a unique_ptr, auto, or shared_ptr), an integer specifying the number of rows, and an integer specifying the number of columns. That’s it. A structure is basically an object (without any member functions), so I’m using an object. Everything else is a function. What are some examples?
newImg = addImages( img img1, img img2 );
newImg = addScalar2Image( float scalar, img img);
I don’t think there’s any ambiguity there. I think this is a much cleaner way to code. As a nice side effect, the code becomes much faster (using objects takes a performance hit).