Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Yep! That's happy path/golden path/line of sight programming, and it's awesome.

https://medium.com/@matryer/line-of-sight-in-code-186dd7cdea...


Nice, 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!?"





Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: