Hacker News new | ask | show | jobs
by keedon 2808 days ago
I think it would help with clarity - too much nesting in a function can mean it's doing too much and might need splitting into several functions
1 comments

One place where nesting makes things difficult is in error handling.

If at each potential error point you best one level, you quickly find yourself deeply nested.

I find the pattern of exiting early and having the “happy path” running to the end of the scope to make it much easier to comprehend a function (I’m sure there’s a term for this coding style but I can’t find the name of it at the moment).

I also find myself doing a similar thing in loops - 'continue'ing early instead of wrapping everything in conditionals.