r/linuxadmin • • Feb 27 '23

GOTOphobia considered harmful (in C)

https://blog.joren.ga/gotophobia-harmful

[removed] — view removed post

0 Upvotes

7 comments sorted by

1

u/[deleted] Feb 27 '23

The person who wrote this blog is an idiot.

3

u/paulstelian97 Feb 27 '23

I'd say goto is fine for stuff like error cleanups. But I'll say that most examples of "backwards goto" are questionable at best (the Linux kernel has a small number of examples, namely a reset label which would be the only label used with backwards gotos)

5

u/IOI-65536 Feb 27 '23 edited Feb 27 '23

I've only ever used goto for error cleanup (specifically reference cleanup writing Python extensions in C)

Edit: I should note though, that to at least that extent I agree with the author (though I think most of what he says are bad uses). I have had people chastise me for using Goto to cleanup references because you should never use a goto. We have been teaching blanket "goto bad" for decades now and at least with respect to error cleanup it's frequently by far the cleanest solution. Definitionally you can't make a function call to cleanup local variables.

0

u/pdp10 Feb 28 '23

You've elucidated your objections so clearly, compared to the expository article with cited references and state-machine diagrams in DOT. /r/C_Programming could benefit from your wisdom.

1

u/[deleted] Feb 28 '23

That goes for you too.

1

u/pdp10 Feb 28 '23

But I'm not objecting to anything. I thought the post was marvelous.

1

u/[deleted] Feb 28 '23

I stand by my assessment.