2 ms·
If you are working in C (not C++ with RAII), return early is a huge headache and maintenance hassle. Basically you want to free any loose buffers on any exit p
by asveikau 9y ago
If you are working in C (not C++ with RAII), return early is a huge headache and maintenance hassle. Basically you want to free any loose buffers on any exit path out of the function, and if you only have one place out of the function, you only have one place to put it.
Or, as I think of it sometimes, if you have N buffers and M early exits, you need O(NM) free statements. When the code changes over time with more exit paths, you need to change that many places. So best to make M=1 for greatest sanity.
A language that does this for you more automatically (either RAII, or GC) then sure, early exit away. Although, one further point I do like about the more explicit C style is you end up writing code that looks very similar in the failure path and success path, which makes you prepared for when things inevitably fail...