If you're going to use C++...

Published April 06, 2007
Advertisement

For the love of whatever it is that you find holy, if you're going to write C++ code, use C++ constructs. Groundbreaking, I know.

I'm sorry, but this has to be one of my biggest pet peeves as a C++ programmer. Especially as one who has to deal with this shit on my game project. Lets look at an example. Something nice and easy, like adding a button to the UI. Now, if it were up to me, the steps for adding a button would look something like this:
1. Create new button object.
2. Add new button to the appropriate menu object.

Now, this is, to some extent, how it used to be done in my current project. Then the UI code got re-written. Now, the process goes a little something like this:
1. Declare global button in one .cpp file.
2. In that same .cpp, be sure to add a call to DeleteButton(whatever the name of the new button is); in the DeleteButtons() function. If you forget this step, you will get a memory leak.
3. In the corresponding .h, extern the new button.
4. In a different .cpp, find the appropriate InitX() function (where X is the menu, e.g. the main menu, in game menu, etc), and call SpawnButton() for the new button.
5. In the DisplayMenu() function, look through the couple hundred line switch statement and find the correct state for the menu the new button is in. Add call to DrawButton() for the new button.
6. But wait, there's more! Still in the DisplayMenu() function, check if the new button is highlighted. If it is, add all code to deal with the button being clicked.
7. Don't forget to add the call to CheckButtonHighlight() in the CheckHighlights() function, or else there will be no way to check if the button is ever pressed.
8. Realize you have to add another button in the game. Weight options, and realize that killing yourself would be much less painful.

Honestly, if you're going to program in a language, learn how to use the bloody language, not some sick, twisted degenerate version of it. And don't give me any of that bullshit about C++ features being slow. Especially when, asked if you've done any profiling to prove this, you're only response is "No, I just know they're slow."


Sorry for the rant (but I had to say something), regular services will resume soon.
0 likes 1 comments

Comments

Mike Bossy
You're describing the young ego of many poor programmers. The sad thing as they get older and get past the idea of C++ being slow they will join the group of pre-mature optimizers who think that the compiler produces bloated and slow code for anything.
April 06, 2007 09:17 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement

Latest Entries

/facepalm

1636 views

Baby Steps

1204 views

...

720 views

Stuff

1236 views

Productivity++

1128 views

Rock Band FTW

1165 views

Seattle Opera

1208 views

Christ

1133 views

I maek gaem!

1111 views
Advertisement