17 comments

[ 2.2 ms ] story [ 48.1 ms ] thread
"goto operator in C? It can be simplified. This code smells! He probably should go and work for Starbucks."

The use of 'goto' in C to separate error-handling code from main-line code is a commonly accepted practice.

Also, "goto" isn't an operator.

I wouldn't hire this person. And I'm not talking about Linus.
Ok, here's what I got from this - Roman can't spell and doesn't understand how to code in C. Fail?
When I was working with GStreamer, gotos of this sort were all over the main workhorse functions in the common elements.
I'll use the "vouch" function for the first time ever, because if you think Roman's an idiot, congratulations, you're in the running for World Champion of Missing the Point.

Lest you doubt me, let me quote the final sentence which you probably didn't read after the first, and impulsively felt the need to run back to HN and show everyone how smart you are: "Author of this code is Linus Torvalds. This world is not perfect and your judging based on small peice of code just doesn’t work."

IOW, Roman might very well know C better than you do, and ironically folks like you might be the reason he wrote the post in the first place.

I flagged this submission because it was provocative (w/ linkbait title) with no proportionately intellectual or insightful payoff.
Eh, good point, it was a bit thin on content. I probably should have let sleeping dogs lie.

As for the other comments, I'm thinking I'm reading this quite differently than others. That's cool, that's why we have a voting system I guess.

It's not clear without more digging who the original author of the code is. Somebody pointed out that it's from drivers/usb/core/hub.c, but the blame history doesn't go further than the initial commit of the repository. That's why it's attributed to Linus Torvalds.

Most likely, the code evolved in a way that makes the goto look sillier than it did in the original version of the code.

I think people understand Roman's point -- they're simply disputing his first paragraph, namely that:

- the code is "awful"

- the programmer "doesn’t know basics"

- "goto statement in C" is somehow anathema

Someone should send this to Linus for some juicy popcorn.
Seems just like click-bait, author makes a point but doesn't really go in depth or explain his thoughts. And it only works because the author tries to mislead you : 'This code smells' Why does it smell exactly? Why should he work at Starbucks?Don't judge a book by its cover, don't extrapolate on a single data point, or a single piece of code, got it.
`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."

Agree 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).
Often 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.
Check 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.
I suppose I should be happy that some Fortran code I wrote back in school wasn't in Github. One of the things I look for in people is their ability to learn, and to do that they have to challenge themselves, to re convince themselves when they do something that it is still the right thing to do, the right path to take, and when they discover new information or new insights they adapt their behavior appropriately.

It makes me wonder if folks growing up in the permanent digital foot print age will be able to escape their early years. There is a reason police records for minors are often sealed, so as adults the things they did as kids don't permanently stain their lives. It is the basis for the right to be forgotten movement in the EU as far as I can tell.