Where to find 'Real' programmers online?

There are places a goto is the only way, but it is a tool.
1) gotos are 100% avoidable, and hence not the only way.
2) From the point of view off efficiency, they are probably better code.
3) Where "while" and "for" are natural, better to use them.
4) better a "goto" than forced "while" or "for" with tricks for avoiding "goto".
5) I would say that a "while", a "for" and similar are more a "tool" than a "goto".
 
1) gotos are 100% avoidable, and hence not the only way.
2) From the point of view off efficiency, they are probably better code.
3) Where "while" and "for" are natural, better to use them.
4) better a "goto" than forced "while" or "for" with tricks for avoiding "goto".
5) I would say that a "while", a "for" and similar are more a "tool" than a "goto".
1) I disagree.
2) I disagree.
3) I disagree.
4) I disagree.
5) I disagree.

Save the GOTO!
 
1772545301424.png
 
In C you have no real choice. You need goto to jump out of nested loops and you need it to skip to a cleanup section at the end of a function.

Both would be easily avoided with language constructs but alas they are not.
 
But that is like a label and a goto!!!!

It's not because you (and the compiler) know that the goto does not jump to e.g. another function, or backwards, or other nasty things.

Also, at least in the Common Lisp version of this you can return a value from such a block.
 
You need goto to jump out of nested loops and you need it to skip to a cleanup section at the end of a function.
Well not only to jump to a cleanup section, but to a place where many jumps converge, forward or backward.
It seems these trivial things are not clear to those that never programmed something like FORTRAN / assembler.
 
we are arguing about gotos 57 years after Dijkstra’s “Go to statement considered harmful”? Real programmers don’t waste time discussing such tired old topics; they write working code!

I once wrote an emulator for motorola 68hc11 in C. Using gnu C’s computed goto extension instead of “for ( ;; ) switch (memory[instnPtr++]) { … }” I doubled the performance! I used 2 or 3 #defines to select the right code depending on the compiler used and to make rest of the code look more “structured” and easier to read.
 
When I was studying Computer Science in college, using Java, I was taught to avoid the GOTO, even though that was in the Java API back then. Thing is, GOTO is not the only way to produce spaghetti code. Hell, if you look at the dependency graphs of installed FreeBSD ports, you'll see that those graphs look a lot like spaghetti, and it's possible to specify circular dependencies.

When I was in high school, learning BASIC, the GOTO was a simple and basic command to know. And back then, the programs written with BASIC were nowhere near long enough to get anyone to see the GOTO as the root of all evil.
😩
 
Goto in C++ is rarely needed. Instead RAII should "undo" memory / resources allocated for unhealthy codepaths.

However for C, it can help to avoid a lot of repetitive (and thus potentially erroneous) code. For example in a function that allocates 5 things, if any one of those fails to allocate, you would have to remember to de-allocate the previous ones, this would end up ~10 lines of repetitive statements. In this case, a goto cleanup could be better.

Some examples of this process are here:

and a more extreme one here (I would personally recommend better names than bad, bad2, bad3, etc:

"Backward" goto is almost never needed though.
 
can't wait for defer to land in modern C compilers tbh
In many cases, if a function is fully successful, you don't want cleanup. You return the newly allocated memory / resource as well as the other allocations underpinning it. Whereas a defer would incorrectly clean it up, even on success leading to a dangling pointer.

So defer could be nice... but for it to be really useful, it would been to be a "cancellable defer". And that is rare in programming languages.

zig, go and C don't. I think Kotlin does with CompletableDeferred but thats JavaVM so the GC should probably just be used anyway.
 
Well not only to jump to a cleanup section, but to a place where many jumps converge, forward or backward.
It seems these trivial things are not clear to those that never programmed something like FORTRAN / assembler.
Thus is the shame. It goes to how they teach computer science these days. Sigh. I think now you can see that the correct use of an unconditional jump (ie GOTO) is a fundamental concept that is misunderstood and somewhat irrationally shunned.
 
Back
Top