Viewing a single comment thread. View all comments

jphamlore t1_iy6qayo wrote

> The debate went on for more than a decade, but in the end, the GOTO went extinct, and no one today would argue for its return.

Has this person ever looked at Linux kernel code written in plain old C?

goto is used all over the place for cleanup after errors, and also frequently for restarting loops.

34

shavetheyaks t1_iy78ycb wrote

I hate this article too (all the "examples" they give are exaggerated and abstract, and halfway through it turns into a not-so-subtle ad for their company), but I would argue that having to use goto for those things is a (soft) flaw in the C language.

My understanding of structured programming is that they took uses of goto and built them into the language to make it easier for the compiler/programmer to reason about them. Error handling and loop restarting are structured patterns that could have been added to the language itself.

Those patterns are so few and easy to reason about that I don't think there's any reason to add things like try/catch to C, but I don't think the presence of goto in C code means that goto is necesssary or desireable (except maybe for the crazy context-switching code you'd see in an OS).

7

Deadmist t1_iy8y9cu wrote

It's been 50 years since C was released. We simply have better options than using goto in modern languages.

2

shavetheyaks t1_iyagi6f wrote

The problem is that modern languages still don't target C's niche (systems and embedded) as well as C does. So we're stuck with it for those cases until something else comes along.

The only thing I know of that's trying for C's niche is Rust, and it's still not ready for it yet, IMO.

2

eras t1_iy84n7n wrote

> goto is used all over the place for cleanup after errors,

That is also the case in Xorg, and it has been a contributing factor for many resource release bugs.

2