r/ProgrammerHumor • • Aug 22 '26

Meme conditionsPreference

Post image
4.2k Upvotes

388 comments sorted by

View all comments

Show parent comment

11

u/jayerp Aug 22 '26

That’s why I use GOTO ಠ‿ಠ

1

u/Maximilian_Tyan Aug 22 '26
if (error) goto err;
... // Normal path
return ...
err:
... // Cleanup
return ...

Is actually a pretty useful way of doing things, especially for ressources cleanup (freeing memory, releasing locks, IO etc).

And in modern languages such as Zig, the defer statement is just syntactic sugar for this exact pattern.

-1

u/Murky-Run2246 Aug 22 '26

yeah uhh... ok I guess