I think I wrote an article a few months ago comparing C and python. I’m doing some new iPhone games now, and this time I’m using C++. I found not having classes was getting to be too painful for me, so I’m trying out C++. Here are a few things I’ve observed:
(As a side note – I’m writing my games /almost/ the same way I’d write them in python. So if you’ve seen my game code, I’m doing almost the same stuff, except in C++.)
- As usual, not having memory management is a bit of bother. Fortunately, I’ve found there are only a few places where I actually need it. The main thing I had to do was write some basic reference counting code for my state engine class.
- I’m using structs instead of classes, since I have no use for private variables or methods.
- Having separate .h and .cpp files is a drag. But them’s the breaks .. It sure would be swell if C++ was a wee bit smarter about that.
- For my in-game objects, I just define a single struct that has all the possible variables I need. This is pretty much how I did things in python anyways. I’ve never been a big fan of using much inheritance.
- For writing my GUI classes, in python I was able to get lots of magic into them. In C++ it isn’t so easy to get magic, so I’m doing without most of it. It seems that most of the magic was gold-plating anyways.
- Having written all this code in python before, getting clean C++ code seems pretty natural. I know what I WANT my code to look like, so I try to get my C++ to be as close as possible to that.