4 ms·
That's a reaction to deep if-else's - and they can happen in the happy path, independently of error handling. I don't recall this requiring much code mangling
by lttlrck 3y ago
That's a reaction to deep if-else's - and they can happen in the happy path, independently of error handling.
I don't recall this requiring much code mangling though?
It means defining the return variable at entry and set its value to the "failed" value (eg NULL or false) and return it once at the bottom.
So you only touch the return on the happy path which reduces the number of error related else's, can reduce the need for guards too, it's consistent and you don't get caught out by early returns.
I still use this when it suits the application.