3 ms·
For code generators, sure. For code written by humans, never.
by preseinger 4y ago
For code generators, sure. For code written by humans, never.
- aaaaaaaaaaab 4y agoI guess you don’t use Linux much, because its codebase has tons of gotos.
- maccard 4y agoWhich are only needed because of C's lacking featureset. RAII (c++'s choice, and my personal favourite) and defer (go uses this and it's fine but is more limited), are both far superior to goto for error handling.
- yakak 4y agoYes, for cleanup at the bottom of functions goto is the go to. I think C limits one to using goto or something worse, but there's a good argument that you could go to rust instead.
- Gibbon1 4y agogoto is better than exceptions because goto is scoped.
- kaba0 4y agoThey are orthogonal features. Also, exceptions are not long jumps either, they have well-defined semantics of only traveling through the call stack.
- preseinger 4y agogoto is generally _unscoped_, the languages in which it is scoped are exceptions. Right? goto in C is unscoped, afaik?
- Gibbon1 4y agoIn C goto is scoped. void Foo(int x) { if(x == 10) goto goof; // don't work. } void Baz(void) { goof: printf("goof isn't in scope"); }
- preseinger 4y agoTIL