logoalt Hacker News

mort96yesterday at 10:11 AM1 replyview on HN

I hate that you can't call defer in a loop.

I hate even more that you can call defer in a loop, and it will appear to work, as long as the loop has relatively few iterations, and is just silently massively wasteful.


Replies

usrnmyesterday at 10:18 AM

The go way of dealing with it is wrapping the block with your defers in a lambda. Looks weird at first, but you can get used to it.

show 1 reply