How do you name your GoTo labels? I use rarely often so I'm having a hard time finding good names.
Please refrain from the classical 'goto is evil and eat your code alive discussion'
How do you name your GoTo labels? I use rarely often so I'm having a hard time finding good names.
Please refrain from the classical 'goto is evil and eat your code alive discussion'
In batch files I often use HELL.
Like:
some_command || GOTO HELL
...
HELL:
echo "Ouch, Hot!"
My label names almost always fall into one of these patterns:
I usually only need it for 2 cases. As such, my goto labels are either begin or finally.
In fortran, I use goto for rollbacks, and I normally start from 999 backwards (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 labels greater than 1000 if for some reason I want to skip the rollback part.
In C and other languages, I would use rollbacknumber (eg. rollback1, rollback2), so it's clear from the label that you are going to rollback. This is basically the only good reason for using goto.