by yk · 4y ago · 0 comments
There is a reason why it was introduced in Go.
It seems barely more implicit than expression-3 in a for loop.
I don't feel like it's going too far for C.
Pragmatic point of view:
In 99% of cases, the developer doesn't care what the compiler produces and doesn't have to. A mechanism providing a complex control flow in the compiler output but is incredibly easy to read and reason about in the source code is useful in the vast majority of cases.
And for the 1% of cases where the programmer actually needs to know what the compiler produces, and / or full control over the control flow, the solution is simple: don't use `defer` and there, done, full control to the developer.
So where exactly is the downside?
And besides, if resources aren't released in the same function you'd need to come up with a different way to clean up anyway.
Not in the standard, but there are compiler implementations (like Microsoft’s) that have added it.