3 ms·
To me, your example is not really easier to understand than the defer version. The complete flow is immediately apparent in your example, but the "effective" f
by avianes 6y ago
To me, your example is not really easier to understand than the defer version.
The complete flow is immediately apparent in your example, but the "effective" flow (the two malloc and the mutex) is harder to identify.
And now imagine the same thing with 10 or more nested conditions.
With defer or goto, it allows you to mentally split the logic in two parts: on one hand the "effective" algorithm; and on the other hand the resource release.