3 ms·
> '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 s
by genwin 14y ago
> '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.
- drivebyacct2 14y agoI 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.
- genwin 14y agoYou're right, it would have to be a new syntax.