
An empirical study of goto in C code - declan
https://peerj.com/preprints/826v1/
======
cms07
This study is ridiculous. Dijkstra's paper was written before C was. There's
no reason to believe that he was referring to the style used commonly in C
code.

Edit: I just mean the tone the study writer takes is ridiculous. It is good to
know that goto is used thoughtfully.

~~~
jerf
We can go stronger than that. The real point of Dijkstra's paper was to argue
in favor of structured programming. C is a structured programming language.
Dijkstra won so thoroughly that we've collectively forgotten what he was
arguing about.

To replicate the goto that Dijkstra was complaining about in C, you would have
to put the entire program in the main function, use no for loops or switch
statements, and use if statements with bodies that only jump to labels and
contain nothing else in their bodies. Nobody programs like that for their
entire program. Dijkstra won.

(On occasion, people structure a function as a state machine rather than a
stack, but generally only in special circumstances. C-style error handling is
also simply using the language tools to implement exceptions, not unstructured
programming.)

~~~
austinz
> We conclude that developers limit themselves to using goto appropriately in
> most cases, and not in an _unrestricted manner like Dijkstra feared_

So this is pretty much the control flow equivalent of someone complaining
about memory errors in languages like C (dangling pointers/memory leaks), and
then much later some academics look through some code written in a managed
GC'ed language like Java or C# and decide that the original complainer really
didn't have anything to worry about.

~~~
jerf
Yup, that's it.

------
yanowitz
Fun paper. I conclude that the warning worked: goto is used carefully and with
restraint.

I suspect you could generalize this to many similar language construct and
tool warnings/anti-patterns.

Except csh. It's always harmful.

------
failrate
I subscribe to the theory that the average use of goto in the sample set is
not toxic because of Dijkstra's warning.

------
frozenport
Don't forget that `Dijkstra` let you GOTO anywhere you wanted, something
impossible in modern implementations.

