4 ms·
So looking at the example, you can avoid one level of indentation by doing e.g.: if (items === null) { return 0; } at the start. Which is fine if that's the
by mnarayan01 10y ago
So looking at the example, you can avoid one level of indentation by doing e.g.:
if (items === null) { return 0; }
at the start. Which is fine if that's the preferred style, but if it is, then you should do it regardless of how deeply nested the dependent stuff is.
- mplewis 10y agoYep! That's happy path/golden path/line of sight programming, and it's awesome. https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea88#.m3qqyv35i https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea...
- moonshinefe 10y agoNice, I didn't know there was actually a name for it. My 15 years of coding experience has just taught me it's the far better way to code. It's one of my peeves to be following code paths and oh look, now we're in a situation where it's if (OK) { if (OK) { if (OK) { if (OK) { ... } } } } and I'm trying to remember what all the conditions were to get here since it's long since scrolled off the page. I always find myself thinking "why, why didn't you just return way up there!?"
- shthed 10y agoother names for it: http://wiki.c2.com/?ArrowAntiPattern http://wiki.c2.com/?ArrowAntiPattern http://thedailywtf.com/articles/Coding-Like-the-Tour-de-France http://thedailywtf.com/articles/Coding-Like-the-Tour-de-Fran...