Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
something likelike what
imo the main use case for goto is breaking through multiple layers of nested loops, for everything else there's better options
setupcode1()
if (somethinggowrong)
goto td1;
setupcode2()
if (somethinggowrong)
goto td2;
setupcode3()
if (somethinggowrong)
goto td3;
setupcode4()
if (somethinggowrong)
goto td4;
dostuff()
td4:
teardowncode4()
td3:
teardowncode3()
td2:
teardowncode2()
td1:
teardowncode1()
Yeah I did a tardery. Don't drink and post.My goodness, no. I cited the context of the paper: go to statements. This is Knuth firing back at Dijkstra's "Go To Considered Harmful", and is Knuth explaining that, no, GOTO commands are just fine, and shoehorning other control flow methods into the space where GOTO fits naturally is bad practice.
Some reading materials, because apparently people in this thread are illiterate.
https://archive.org/details/Structured_Programming__Dahl_Dijkstra_Hoare - Structured Programming by Dahl, Dijkstra, Hoare
https://homepages.cwi.nl/~storm/teaching/reader/Dijkstra68.pdf - go to Considered Harmful by Dijkstra
https://dl.acm.org/doi/epdf/10.1145/356635.356640 - Structured Programming with go to Statements by Knuth
If you think that mathematicians keep a standard for denoting first element you are mistaken. Infact it is even less standarized than in programing as most often it is whatever is most convinenthonestly i believe if arrays werent a syntax sugar over a pointer but their own object/abstraction they would start at one, since in mathematics first element of something is denoted using a "1" not "0"
but it does make math a little bit wonky, for example taking a mod of something would require adding a one and such
I think we read different papers. Because Knuth is stating quite clearly that goto should be the last resort for when higher level control flows do not suffice. And even then the first question should be whether you are thinking about problem in right manner.My goodness, no. I cited the context of the paper: go to statements. This is Knuth firing back at Dijkstra's "Go To Considered Harmful", and is Knuth explaining that, no, GOTO commands are just fine, and shoehorning other control flow methods into the space where GOTO fits naturally is bad practice.
Other than that recursion elimination is solved by tail call optimization nowadays.He taught them to use go t o
only in unusual special cases where i f and
w h i l e aren't right, b u t he found [78] t h a t
"A disturbingly large percentage of the
students ran into situations t h a t require
go to's, and sure enough, it was often because
w h i l e didn't work well to their plan, b u t
almost invariably because their plan was
poorly thought out." Because of arguments
like this, I ' d say we should, indeed, abolish
go t o from the high-level language, at least
as an experiment in training people to
formulate their abstractions more carefully.
This does have a beneficial effect on style,
although I would not make such a prohibi-
tion if the new language features described
above were not available. T h e question is
whether we should ban it, or educate against
i t ; should we a t t e m p t to legislate program
morality? In this case I vote for legislation,
with appropriate legal substitutes in place
of the former overwhelming temptations.
its great to see people were calling things "literally 1984" even before the internethttps://dl.acm.org/doi/epdf/10.1145/356635.356640 - Structured Programming with go to Statements by Knuth
thats how APL niggers actually genuinely unironically write c btwWhy even bother with array indices? Any decent language worth using has support for foreach.
C:#include <stdio.h> #define foreach(e,a)for(__typeof__(*a)*e=a,*a##_last=(a+(sizeof(a)/sizeof(*a))-1);e<=a##_last;++e) int main(void) { int xs[]={1,2,3,4,5}; foreach(x,xs)*x=*x%2?*x*3+1:*x/2; foreach(x,xs)printf("%d%s",*x,x!=xs_last?", ":"\n"); }
This might look hideous, but this is next level memory management which saves multiple bytes of disk space by removing extranous whitespace and using minimal variable names. But I guess this sort of thing would probably go over the heads of a bunch of cave-dwelling webdevs who only know JavaScript...![]()
something like
Code:setupcode1() if (somethinggowrong) goto td1; setupcode2() if (somethinggowrong) goto td2; setupcode3() if (somethinggowrong) goto td3; setupcode4() if (somethinggowrong) goto td4; dostuff() td4: teardowncode4() td3: teardowncode3() td2: teardowncode2() td1: teardowncode1()
Can be useful for handling cleanup code.
yeahthis feels like the type of thing that raii was made to avoid
gcc manual said:cleanup (cleanup_function)
This attribute applies to variables.
The cleanup attribute runs a function when the variable goesout of scope. This attribute can only be applied to auto functionscope variables; it may not be applied to parameters or variables with static storage duration. The function must take one parameter,a pointer to a type compatible with the variable. The return value of the function (if any) is ignored.
When multiple variables in the same scope have cleanupattributes, at exit from the scope their associated cleanup functionsare run in reverse order of definition (last defined, first cleanup).
Yeah, in most languages these days it isn't relevant. But in something like pure c, it does often make sense.this feels like the type of thing that raii was made to avoid
You're taking my comments out of context. Here is how the Conclusion begins.I think we read different papers. Because Knuth is stating quite clearly that goto should be the last resort for when higher level control flows do not suffice. And even then the first question should be whether you are thinking about problem in right manner.
I think it's perfectly acceptable interpretation given modern context, especially given that he himself states that "new types of syntaxes are being developed"."should be the last resort" is stretching what Knuth is saying here.
I don't think I would interpret what Knuth is saying as this. I honestly believe he has opposite intention from this text, especially if you read later part of his conclusion which talks about students.My statement "GOTO commands are just fine" shouldn't be read as "GOTO commands are always fine", but more that "GOTO elimination" as a dogmatic belief is an instance of premature optimization.