Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Why doesn't anyone use Goto anymore?


  • Please log in to reply
21 replies to this topic

#1 Donovan

Donovan

    CC Devotee

  • Senior Member
  • PipPipPipPipPipPip
  • 633 posts
  • Location:Nevada
  • Learning:Java, Objective-C, PHP, JavaScript, Perl, PL/SQL, ActionScript, VBScript, Others

Posted 09 September 2009 - 08:39 AM

Why doesn't anyone use a goto statement anymore?

where ever you put goto name; it will go to any section with

name:

So for example.

BLOCK OF CODE HERE
goto name;

BLOCK OF CODE

BLOCK OF CODE

name:
(It would then start at the next block of code after name.)
BLOCK OF CODE


This will work up or down. For example.

mainMenu:
BLOCK OF CODE

BLOCK OF CODE

BLOCK OF CODE

goto mainMenu;
  • 0

#2 dcs

dcs

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 730 posts

Posted 09 September 2009 - 10:20 AM

Because other programming structures largely make goto kludgey and irrelevant, relegating "proper" use of goto to very few situations. The ones you show are not them. ;)
  • 0

#3 ZekeDragon

ZekeDragon

    CC Leader

  • Retired Mod
  • PipPipPipPipPipPipPip
  • 1263 posts

Posted 09 September 2009 - 10:27 AM

Goto also can't be used to go into a try statement, making it's practical use in C++ very limited.

Goto is also difficult to read, since there's no way for you to know where that label is short of some kind of very detailed IDE.

I believe there may be uses for Goto... I've just never seen them.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#4 dcs

dcs

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 730 posts

Posted 09 September 2009 - 11:41 AM

An article I stumbled upon: Code Complete, First Edition
  • 0

#5 debtboy

debtboy

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 499 posts

Posted 09 September 2009 - 12:35 PM

I used to use it a lot in basicA
and occasionally in QuickBasic,
since then I haven't used it.
(whoops... showing my age)
  • 0

#6 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 September 2009 - 01:07 PM

QuickBasic... the good old days when you could start a loop at 0 and poke 0 into the loop variable :) Until DOS froze, that is.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#7 BlaineSch

BlaineSch

    CC Leader

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1559 posts

Posted 09 September 2009 - 03:18 PM

I think goto just makes it terribly hard to read and maintain code. Structured programming took over.
  • 0

#8 debtboy

debtboy

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 499 posts

Posted 09 September 2009 - 04:48 PM

QuickBasic... the good old days when you could start a loop at 0 and poke 0 into the loop variable :) Until DOS froze, that is.

Yea, back when you could output whatever binary pattern you
wanted on the bits of your printer port w/ only 1 command!!
The good old days... :D
  • 0

#9 Aereshaa

Aereshaa

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 638 posts

Posted 09 September 2009 - 05:20 PM

People don't use goto because of the very good reasons given by Edsger Dijkstra in his article: "Goto Statement Considered Harmful".
I think the only justifiable gotos in C are in lieu of exceptions. In any case, one should just use setjmp.h
  • 0
Watches: Nanoha, Haruhi, AzuDai. Listens to: E-Type, Dj Melodie, Nightcore.
"When people are wrong they need to be corrected. And then when they can't accept it, an argument ensues." - MeTh0Dz

#10 cdg10620

cdg10620

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 344 posts
  • Programming Language:C#, JavaScript, PL/SQL, Transact-SQL, VBScript, Others

Posted 09 September 2009 - 05:55 PM

One thing that I forget to keep in mind when developing is that I may not always be the person working on the code I'm writing. This sometimes results in code that is messy and hard to maintain due to bad naming, structure, or lack of clear comments.
  • 0
-CDG10620
Software Developer

#11 dcs

dcs

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 730 posts

Posted 09 September 2009 - 06:42 PM

I think the only justifiable gotos in C are in lieu of exceptions. In any case, one should just use setjmp.h

Ick.

/imo
  • 0

#12 Termana

Termana

    CC Devotee

  • Just Joined
  • PipPipPipPipPipPip
  • 971 posts

Posted 10 September 2009 - 02:07 AM

Goto can make code hard to follow, or drag functions out when it could be split into two (or more) functions. It can also make modifying code hard. IMO.
  • 0

Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download