https://github.com/torvalds/linux/blob/f4bc5bbb5fef3cf421ba3...
github.com/user/repo/blob/master/foo/bar/baz.py
But this file can change, meaning this url might not have the same content a week or month down the road. This is particularly troublesome when you have lines selected. To fix this, press `y` and your url will get expanded to include the current commit hash: github.com/user/repo/blob/e4ecae.../foo/bar/baz.py
Now your URL is safe to share.i.e.
https://github.dev/torvalds/linux/blob/f4bc5bbb5fef3cf421ba3...
https://github1s.com/torvalds/linux/blob/f4bc5bbb5fef3cf421b...
1. You're using the goto for error handling and cleanup in a function; and
2. You only jump in a forward direction.
Seeing even one goto jumping backward would be much more surprising, and seeing what made gotos get their bad rep, overlapping goto regions, would be completely shocking in any quality code base.
- if-statements
- switch-statements
- break
- continue
- exception handling
The whole "gotos are bad" really needs to die.
https://github.com/torvalds/linux/blame/f4bc5bbb5fef3cf421ba...
The other option, in functions like this, is to have duplicated "deferred" execution scattered throughout the function at each return point. This is a maintenance nightmare as it can be hard to discern which code is actually part of the "deferred" block (and needs to be copied) and which isn't, at least at a glance. So differences in two return points are clues that something may be wrong, but requires further investigation to determine if they should or should not be the same. As a function grows in size, this becomes increasingly problematic.
It's actually a good demonstration of DRY.
Also, apart from straight-line functions it's hard to avoid goto at the machine code level.
However, they do improve the maintainability of the code. I find it interesting, looking at them and having done a quick reread of Knuth's take on goto statements (for another comment I made here) that these uses correspond to what other languages possess as syntactic elements in the structured programming vein, which is one of the things he discusses in favor of both structured programming and goto statements. In favor of structured programming, you get new syntactic elements that provide useful semantics that make the code clearer. Why are we doing this jump? Oh, it's a conditional (if/then/else) or a loop (for, while). But when you lack the syntax and semantics for that, the goto statement can fill in the gaps (when used carefully, deliberately).
Specifically, out mostly corresponds to defer (in Go) or finally in other languages. error is like try/catch/finally in Java and others. unlock_out would be like the with statements you get in some other languages.
EDIT: Reexamined this specific source file. Most of the out sections are 0-2 statements in addition to the return. So in the 0 case, there ought to be a performance improvement by just returning, though I imagine a compiler can optimize the goto's away. In the 1-2 statement range it'd be a tossup on whether the increase in function size would cost more (cache miss and similar) than the indirection itself costs. I only saw one (it's a large file, I didn't look too closely) that had a larger out section than 2 statements, and that one had enough that the indirection is probably worth the performance cost.
But, in all cases (except the 0-statement case) it still is better from a maintainability perspective, whether or not it helps performance. In the 0-statement case, I wonder if they're vestigial. If there were other statements included that were dropped for some reason. But I'm not going to dig further into this because now it's time for me to study.
Probably easier to throw the whole thing out and start again.