I've heard a lot that using Goto is bad. But how bad is it? I'm adding a main menu to my game, and though I've got it working with a 'while', its complicated and I'd really like to do something like this:
It would be so much cleaner to just have the menu and game as state objects, and then just call menu->run() or game->run() whenever you need to.
The main problem with goto is that it makes code crazy and hard to read. If you use it in a few clear places and keep the structure very intuitive and readable, then I think that you should feel free to use it.
You will hear lot of things to be bad while you will learn C++. True is, they are bad mostly in some context. They might be good in other. Look at goto as a tool on your disposal ...use your own brain and opinion on if and when to use it or not.
You will hear global variables to be bad too for example. There is nothing bad on it however and in some cases globals might be the most efficient way to go. Of course they might be bad in other cases.
So my advice is: Do not accept opinions of others without consideration. Do not do it even if they seem much more experienced than you.
In programing, good is what leads you to your goal, preferably the most easiest and efficient way. Bad is what prevents you from getting there.
arras wrote:You will hear lot of things to be bad while you will learn C++. True is, they are bad mostly in some context. They might be good in other. Look at goto as a tool on your disposal ...use your own brain and opinion on if and when to use it or not.
You will hear global variables to be bad too for example. There is nothing bad on it however and in some cases globals might be the most efficient way to go. Of course they might be bad in other cases.
So my advice is: Do not accept opinions of others without consideration. Do not do it even if they seem much more experienced than you.
In programing, good is what leads you to your goal, preferably the most easiest and efficient way. Bad is what prevents you from getting there.
Amen.
In the case of goto, it's the recommended way to break out of nested for loops, and for jumping to other switch statements.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Yes but when you are going out of the way to create separate functions or temporary boolean variables to break out of several loops at once when its inconvenient, thats being a little too pedantic. I mean its not like *gets eaten by dinosaur*
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
As long as you're sure that all the necessary destructors or constructors are called, your values are all initialized, etc. But using a different approach (which might require some additional bools to set some states) seems far more tractable and gives the compiler some additional confidence in the code to allow optimizations.