Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> 'defer' is currently very useful in loops, open a bunch of files in a loop and schedule them all to be closed at the end of the function. If defer was block scoped this would be impossible.

Why couldn't it work at both the function and block level? I too would like to use defer at a block level. I find myself creating functions just to gain usage of defer, or not using it when I'd like to.



I can think of lots of times I use defer in a block where it would be very problematic to have it execute at the end of block rather than end of function. I'm assuming there would be new syntax. That alone I think would be a strong mark against it.


You're right, it would have to be a new syntax.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: