3 ms·
Striving for a single return (without going out of your way to achieve it) is good practice. There are two main advantages: - it's obvious when the function e
by riquito 7y ago
Striving for a single return (without going out of your way to achieve it) is good practice.
There are two main advantages:
- it's obvious when the function ends, no hidden early exits in the middle of nowhere
- if you need to do something before returning, there is only one place to do it (e.g. trim the output, e.g. log performances), and it make it easier to move this kind of last mile logic to a different function (if it's of any interest)
About your interview, don't sweat it, is not for that you didn't pass (you could do a great job and yet lose to a more fit candidate)