Sign in to follow this  
heron3d

would you use a jump statement

Recommended Posts

heron3d    132
I've reached a point is my code where it would be tempting to use a go to: label. Labels have always been frowned upon and this makes me hesitate using them.

I want to make it a habit of writing good code and I'm really at an impasse here. On the one hand, there is the convention and on the other the technical drawbacks. I think if there are no technical drawbacks I would go against convention in this case.

How do you pros feel about labels? And are there any technical drawbacks to using jump statements of this kind?

Thanks in advance
Nikos

Share this post


Link to post
Share on other sites
larspensjo    1561
There are no technical drawbacks. Maybe jumping in and out of scopes can have effects on automatic objects. The drawback with jump statements is that they make it more difficult to follow the flow of control, adding a risk for something going wrong.

Usually, when resorting to using a "goto", it is an indication that the flow of logic has become too entangled. That is the real problem.

See some interesting thoughts at [url="http://c2.com/cgi/wiki?GotoConsideredHarmful"]Goto Considered Harmful[/url]. I should add that this is a discussion that can easily turn into a flame war. But most people probably agree that you should avoid goto as much as possible. Edited by larspensjo

Share this post


Link to post
Share on other sites
heron3d    132
[quote name='larspensjo' timestamp='1339659823' post='4949073']
See some interesting thoughts at Goto Considered Harmful.
[/quote]
That is funny. His guidelines apply in my case. My goto will point forward and will make my code incredibly more easy to understand and it is only used once.

I've decided. thanks. gamedev.net rocks

Share this post


Link to post
Share on other sites

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

Sign in to follow this