5 ms·
returning early is a good practice for all the guards and sanity checks you have to perform before the main logic of the function kicks in. if you use it this w
by zem 15y ago
returning early is a good practice for all the guards and sanity checks you have to perform before the main logic of the function kicks in. if you use it this way, your function will visually consist of a bunch of small blocks each with a return, followed by one larger chunk of code that is the "actual" function, and where you can enforce a single return at the end.
- cema 15y agoI concur. This is how I have been structuring function bodies for a while now, and coworkers tend to easily follow the logic of both the whole function body and the "actual" work.