Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

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

Sign in to follow this  


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.
Sign in to follow this  

1 Comment

Recommended Comments

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.

Share this comment

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!