4 ms·
Goto in C (and worse, setjmp) is almost always a workaround for a deficiency in C. Examples: The "goto cleanup" idiom to do deferred work (I don't like defer o
by tialaramex 4y ago
Goto in C (and worse, setjmp) is almost always a workaround for a deficiency in C. Examples:
The "goto cleanup" idiom to do deferred work (I don't like defer or finally in languages which have them, but at least these are language constructs which say what we wanted, the goto cleanup idiom only achieves that in some very easy cases, in more complicated cases your actual intent will be unclear)
The "iterator escape" idiom to get out of some larger iterative operation we're doing because we just realised we want to give up / found the overall answer. This is lack of imagination in the language's / library's / eco-system's control flow semantics and is one reason I really like Rust's core::ops::ControlFlow.
- bruce343434 4y agoWhat is your proposed alternative for `defer`? (suppose hidden "RAII" control flow doesn't count)
- ncmncm 4y agoIt doesn't. Or, rather, RAII flow is strictly, explicitly better.
- deleted 4y ago[deleted]
- munchenphile 4y agoKotlin‘s return/break@<implicit or explicit loop label> handles the iterator escape idiom quite elegantly.
- dhzhzjsbevs 4y ago> This is lack of imagination Code shouldn't require imagination. Sometimes the simple and readable solution is just better.
- saagarjha 4y agoHow about the "threaded interpreter" idiom?