464
Yeah third party thinker just use your brain duh
(programming.dev)
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Unless you're programming in assembly
I mean, in C too.
I used it when I wrote some throwaway C++ code working with SQLite. Since it had no RAII (and I had no intention of writing my own wrapper), I had to manually cleanup multiple resources somehow. If at least one resource failed to initialize, I had to deinitialize the ones that didn't fail. It was either
goto
or a bunch of flags to track what is initialized.goto
looked more elegant.even if the flags look less elegant you really want to avoid using
goto
’s in pretty much every context in modern C. it basically only exists for backwards compatibility purposes, so all our shit from 1999 doesn’t go up in flames. it is considered bad practice to use it now because it really complicates the control flow logic and it is much less modular/portable.i don’t understand thinking using flags would be less elegant, either. wouldn’t you rather have a neat list of everything for garbage collection purposes than having to search through
goto
statements thrown all around the code?either way, if you’re in this situation in the first place, you’re writing bad C code. memory management should never manifest in implementation like this.
I misremembered the whole thing. It was still related to cleaning up after a failure, but there was only one resource I had to deal with. That's how it looks like:
goto in assembly? nah, might as well JMP
Yeah, it's not called goto, but it's functionally the same.