3 ms·
`goto` to arbitrary labels can be pretty risky. But `goto` to facilitate a single-point-of-exit for a function is a pretty sane idiom. It's all over the linux
by wyldfire 11y ago
`goto` to arbitrary labels can be pretty risky. But `goto` to facilitate a single-point-of-exit for a function is a pretty sane idiom. It's all over the linux kernel and I don't think that anyone regrets it.
So I wouldn't state something like "Even Linus isn't perfect," rather "you should be open minded to learn new development idioms in environments where you're less experienced."
- vskarine 11y agoAgree with you. My first job out of college was working with C code on embedded modem software and when I saw this pattern and was like WTF?! but then realized how useful it is to have single point of exit in a function (especially in embedded systems code).
- Gibbon1 11y agoOften it's very useful to have separate returns from functions for errors. The reason being you can set a break point on the error return and then let the code run. The code will run normally until the error occurs, which in some cases may take days.
- Gibbon1 11y agoCheck out the function it's from, it's a classic function with multiple guard exits and normal return at the end. The gotos to a label in an if block is what's amusing. But you can see why he's doing that, he has exactly one exit per returned error type.