4 ms·
It's too bad goto has been so demeaned. It's great for "we're done here but I always want to do a few things before we exit". Like logging. That's it actually w
by zikzak 5y ago
It's too bad goto has been so demeaned. It's great for "we're done here but I always want to do a few things before we exit". Like logging. That's it actually why I always work to a single return. I like to know, right before I exit, that I can clean references up, or write to a log, or whatever and that only has to happen in one place. If I'm patching some legacy code, I won't usually refactor to achieve this, but I might.
- freemium413 5y agoWhen I come across a situation like that, i consider the chunk of code reusable and split it into a separate function. It may not be perfect and you might need to make that function more generic than it was but I think it makes sense.
- bobbylarrybobby 5y agoSome languages support this with try/finally or a `defer` statement that you can place near the top of the function