GoTo Shortcut Naming Conventions

What do you call your GoTo tags? I often use it rarely, so it's hard for me to find good names.

Please refrain from the classic "goto is evil and eat your alive live discussion"

+4
source share
5 answers

My shortcut names almost always fall into one of these patterns:

  • A "reboot" is called to restart the set of nested loops, because the change made something invalid.
  • "Exit" or "return" is called, right before the return statement, and only there because of the trace statement that registers the return value for debugging
  • Has the same name as the boolean variable that it replaces
+5
source

In batch files, I often use HELL.

how

some_command || GOTO HELL ... HELL: echo "Ouch, Hot!" 
+3
source
  • β€œclean up,” if it is, before releasing some previously allocated resources (or a similar kind of β€œfinally” job)
+2
source

In fortran, I use goto for rollbacks, and I usually start 999 back (in fortran, goto labels are only numeric)

  call foo(err) if (err /= 0) goto 999 call bar(err) if (err /= 0) goto 998 call baz(err) if (err /= 0) goto 997 ! everything fine error = 0 return 997 call undo_bar() 998 call undo_foo() 999 error = 1 return 

I also use tags greater than 1000 if for some reason I want to skip part of the rollback.

In C and other languages, I would use rollbacknumber (e.g. rollback1, rollback2), so it will clear the label you are about to roll back. This is essentially the only good reason to use goto.

+1
source

Usually I only need this for 2 cases. So my goto tags start or end.

0
source

All Articles