Click here to Skip to main content
16,012,061 members

Survey Results

The goto statement.   [Edit]

Survey period: 8 Jan 2001 to 14 Jan 2001

We want to finally put to rest the question of whether the goto statement is a Good Thing or a Bad Thing.

OptionVotes% 
It's a great thing. Can't live without it.111.60
It's handy if used correctly16724.31
It's just a piece of syntax - niether good nor bad.8612.52
I don't like it, but can see why it may be useful sometimes.25136.54
It's a Very Bad Thing17225.04



 
GeneralRe: Error handling Pin
10-Jan-01 8:21
suss10-Jan-01 8:21 
GeneralRe: Error handling Pin
Christian Graus10-Jan-01 18:52
protectorChristian Graus10-Jan-01 18:52 
GeneralRe: Error handling Pin
jkgh11-Jan-01 7:46
jkgh11-Jan-01 7:46 
GeneralError handling Pin
jkgh10-Jan-01 7:53
jkgh10-Jan-01 7:53 
Generalgoto is da bomb Pin
CodeGuy9-Jan-01 2:47
CodeGuy9-Jan-01 2:47 
GeneralRe: goto is da bomb Pin
Chris Maunder9-Jan-01 10:40
cofounderChris Maunder9-Jan-01 10:40 
GeneralHow do you use Goto ? Pin
Colin J Davies7-Jan-01 22:19
Colin J Davies7-Jan-01 22:19 
GeneralRe: How do you use Goto ? Pin
Chris Maunder7-Jan-01 22:40
cofounderChris Maunder7-Jan-01 22:40 
You can use goto in place of do/while/for; you can use it to quickly exit to cleanup code at the end of a function; you can use it to create the most horrible switch statement replacement ever; and you can use it to give your code reviewers coronaries. What more could you ask for in a statement! Poke tongue | ;-P

One thing I have used a goto for is for cleanup. I could have used exceptions, but I wanted performance and was just not in the mood for try/catch statements (I know, I'm fickle).

Instead of:
bool foo()
{
  if (!AllocateStuff())
  {
    CleanupError();
    return false;
  }

  if (!DoThis())
  {
    CleanupError();
    return false;
  }

  if (!DoThat())
  {
    CleanupError();
    return false;
  }

  CleanUp()

  return true;
}

or you could use
bool foo()
{
  do 
  {
    if (!AllocateStuff())
       break;

    if (!DoThis())
       break;

    if (!DoThat())
      break;

    CleanUp();

    return true;
  } while (false);

  CleanupError();
  return false;
}

OR you could use
bool foo()
{
  if (!AllocateStuff())
     goto error;

  if (!DoThis())
     goto error;

  if (!DoThat())
    goto error;

  CleanUp();

  return true;

error:
  CleanupError();
  return false;
}


cheers,
Chris Maunder
GeneralRe: How do you use Goto ? Pin
7-Jan-01 23:43
suss7-Jan-01 23:43 
GeneralRe: How do you use Goto ? Pin
8-Jan-01 8:59
suss8-Jan-01 8:59 
GeneralRe: How do you use Goto ? Pin
8-Jan-01 23:10
suss8-Jan-01 23:10 
GeneralRe: How do you use Goto ? Pin
9-Jan-01 16:03
suss9-Jan-01 16:03 
GeneralRe: How do you use Goto ? Pin
Colin J Davies8-Jan-01 6:11
Colin J Davies8-Jan-01 6:11 
GeneralRe: How do you use Goto ? Pin
19-Jan-01 5:14
suss19-Jan-01 5:14 
GeneralWho needs goto Pin
AlexMarbus7-Jan-01 21:12
AlexMarbus7-Jan-01 21:12 
GeneralRe: Who needs goto Pin
Gavin Greig8-Jan-01 3:37
Gavin Greig8-Jan-01 3:37 
GeneralRe: Who needs goto Pin
AlexMarbus8-Jan-01 5:19
AlexMarbus8-Jan-01 5:19 
GeneralRe: Who needs goto Pin
Gavin Greig8-Jan-01 22:37
Gavin Greig8-Jan-01 22:37 
GeneralRe: Who needs goto Pin
David Wulff8-Jan-01 5:42
David Wulff8-Jan-01 5:42 
GeneralRe: Who needs goto Pin
Christian Graus8-Jan-01 12:03
protectorChristian Graus8-Jan-01 12:03 
GeneralRe: Who needs goto Pin
David Wulff8-Jan-01 12:16
David Wulff8-Jan-01 12:16 
GeneralRe: Who needs goto Pin
John Fisher9-Jan-01 5:08
John Fisher9-Jan-01 5:08 
GeneralRe: Who needs goto Pin
David Wulff9-Jan-01 9:43
David Wulff9-Jan-01 9:43 
GeneralRe: Who needs goto Pin
Christian Graus9-Jan-01 13:20
protectorChristian Graus9-Jan-01 13:20 
GeneralRe: Who needs goto Pin
8-Jan-01 11:53
suss8-Jan-01 11:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.