top | item 47040173

(no title)

renehsz | 13 days ago

This is big news. Defer can simplify control flow a lot, especially in early-return cases like handling errors. No longer do we have to write deeply nested ifs or the madness that is goto. Resource acquisition and cleanup can now be right next to each other.

Now we just have to hope that standardization goes well. The C standard moves very slowly, and that's probably a good thing. But defer is such a simple yet powerful feature that the cost/benefit ratio should easily justify its inclusion.

discuss

order

gustedt|12 days ago

Thanks!

In fact, the standard reflects what is happening in the field. So, use `defer` where this is already possible and ping your compiler vendor for those that do not have it yet. If there is enough demand, `defer` may even happen for the next standard release.