4 ms·
This is actually a feature, not a bug. With defer the control flow is more obvious and predictable. That’s one of the reasons new languages are adopting it.
by typon 5y ago
This is actually a feature, not a bug. With defer the control flow is more obvious and predictable. That’s one of the reasons new languages are adopting it.
- gsliepen 5y agoBut with defer you can easily get the order of things wrong, whereas destructors are automatically called in the correct order.
- watt 5y agoThe advantage of "defer" is that it's explicit. It's right there, and it's crystal clear when it will run. The "implicitness" and hidden nature of destructors is a disadvantage, it's the unpleasant way it can introduce behavior which might be surprising.