6 ms·
Go doesn't have RAII or destructors, it has defer.
by jolux 4y ago
Go doesn't have RAII or destructors, it has defer.
- tedunangst 4y agoWhich definitely does weird things in a loop.
- Groxx 4y agoIIFEs trivially solve that. tbh I see FAR more range-var-misuse with Go loops than defers. I've seen over 100 range-var problems, and seen lints catch many more (several thousand), but I've only seen a loop defer issue once. When a defer is needed, it seems like people both remember the issue better (`defer` is a new construct for many, `for` is not and habits from other languages can mislead them), and the code is complex enough to justify a helper func, where a defer is trivially correct.
- nextaccountic 4y agodefer proposal for C made in 2021 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2895.htm https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2895.htm ... why isn't this in C already?