gotos
Every system needs one
terry at wsccs.UUCP
Thu Apr 28 15:16:50 AEST 1988
In article <1988Apr24.012322.3951 at utzoo.uucp>, henry at utzoo.uucp (Henry Spencer) writes:
> > A language feature is there for a reason...
>
> Language designers and standardizers do have to consider badly-written
> existing code as such a reason, remember.
Standardizers, yes; designers, no. If you degisign a language, then there is
not existing code. ANSI isn't considering "badly written" code, aparrently,
although defining "badly written" in a standard that makes something badly
written is begging the question.
>
> > ...308 "goto"'s in the UNIX kernel. (I checked... NONE were comments)...
> > I thinks this adequately justifies the use of "goto"'s in commercial
> > programming...
>
> Believe it or not, some of us do not consider the Unix kernel a shining
> example of wonderful programming (although it is mostly okay, and it does
> work pretty well).
It would be slower in a number of cases without the construction it has...
consider the generation of "init", fo instance. I wasn't saying it was
wonderful; simply adequate, and in some cases more efficient due to it's
use of goto's...
> > Try the following some time. Replace all your "nifty" flags with "goto"
> > statements, and profile both versions of the code...
>
> If you read the paper by Geoff Collyer and myself in last year's winter
> Usenix proceedings, I think you will realize that I know how to profile
> things, and also how to make them run fast without assembler or gotos
> (C News contains neither).
There are some cases where goto's *SHOULD* be used for efficiency where the
compiler or optimizer doesn't have a snowball's chance in hell of figuring
out what I wrote for itself. Better to hit it over the head with what you
consider a hammer than to be less efficient.
> > then, disassemble
> > both versions and grep for all branch instructions. Which has more
> > REAL "goto"'s?
>
> Personally, I don't care diddly-squat about how ugly the code coming out
> of the compiler is. I don't usually read it. What I care about is the
> cleanliness of the source code, which I do have to read, and the speed and
> correctness of the object code. Turning clean human-readable notation into
> ugly fast code is the compiler's *JOB*.
You don't agree that less of the same instructions == faster code?
Goto's are not the unclean, wearing the red mask of death and knocking at your
door. Are you trying to tell us that you have *NEVER* used a goto?
How does a goto differ from a break statement when used to exit a for statement
to the statement immediately after it... pages of code later? Why can't goto's
be used, in your book, to handle non-standard conditions?
>
> > ... If you use "goto"'s in place of flags
> > which are modified in one place only for the express purpose of avoiding a
> > "goto", you certainly clean up the assembly code, as well.
>
> If you use neither, the source code generally looks still better, and the
> assembler might well improve too (if you care).
I agree with this, it's just that sometimes fugly code must be written
to do something fast and elegantly. I simply think that a goto is less fugly
than an equivalent failure-loop construct, and beats indenting (or worse, NOT
indenting) everything. I happen to write code that uses
for( ;;) {
}
instead of
while( 1) {
}
too, as I need the best speed out of the hardware I can get and the 'for'
avoids a test instruction being generated. Certainly, the 'while' is better
at self-documenting, but it isn't the right tool for the job.
> I'm not sure I've ever used a flag just to avoid a goto; certainly I haven't
> done it recently.
[...]
> I've only programmed in C for 13 years.
What do you write?
> "Noalias must go. This is | Henry Spencer @ U of Toronto Zoology
> non-negotiable." --DMR | {ihnp4,decvax,uunet!mnetor}!utzoo!henry
For someone as vehnemently against 'noalias' as your .sig implies, how can
you berate a current language feature? And how can you respect DMR's concept
of C enough to quote him on it, but not respect his decision to include the
'goto' statement? Your appeal to his authority is a little inconsistent.
| Terry Lambert UUCP: ...{ decvax, ihnp4 } ...utah-cs!century!terry |
| @ Century Software OR: ...utah-cs!uplherc!sp7040!obie!wsccs!terry |
| SLC, Utah |
| These opinions are not my companies, but if you find them |
| useful, send a $20.00 donation to Brisbane Australia... |
| 'Admit it! You're just harrasing me because of the quote in my signature!' |
More information about the Comp.lang.c
mailing list