More C++ stuff…

In my previous post on this blog, I ranted a bit about things I didn’t like about C++, and in an earlier post about a video game I’ve been working on (word war vi), I made a little video talking about some of the implementation details. In response to my previous post, a commenter linked to Yossi Kreinin’s excellent FQA Lite, which is a “Frequently Questioned Answers” site which is a very well thought out and presented critique of C++.

The author also has a blog, “Proper Fixation, a substitute for anaesthesia”.

It is reassuring to me that my own views of C++, even though I am not an experienced C++ programmer, are lining up very well with this guy’s views. Very well indeed. For instance, in one of his entries, talking about doing OO style programming in C, he has this to say:

You can dynamically “change the object type” by changing the vtable pointer. I first saw this in POV-Ray, which has a vtable for circles and a vtable for ellipses. When a geometric transformation applied to a circle object transforms it to an ellipse, the vtable pointer is changed to point to the more generic and slower ellipse rendering functions. Neat. You could do this using C++-style OO by having another level of indirection, but with C, it’s marginally faster, which can matter sometimes. And the C way is much neater, which is useful to balance the frustration caused by the drawbacks of fake OO. I use this trick a lot for debug plugins in my fake OO stuff.

This is almost exactly the technique I independently discovered (not that it’s not fairly obvious) and used in Word War vi for the situation in which the guns which hang down from the “roof” are shot down (I just changed the function pointer, not having a vtable pointer, but the concept is the same.) I simply reassign the function pointer for the “move” action for these guns to be the one normally used for bombs, and by doing this, the guns magically fall down to the ground and explode. I even mentioned this in the video in this post as something I like better about C than C++.

The down side of being “right,” or “vindicated” in my opinions of C++ is that… well, it doesn’t mean that I no longer have to use C++, it just means I’m all too aware of the mess I’m having to deal with. If ignorance is bliss, perhaps I’ve now been deprived of some bliss.

~ by scaryreasoner on August 10, 2008.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: