Hacker News new | past | comments | ask | show | jobs | submit login

To be totally honest? Yes. Co-locating all the conditions makes it easier to comprehend at a glance. There are obvious drawbacks, but I lean toward this style more and more.

Consider the case below. If I want to understand what conditions are necessary for body, that code is now offscreen. I generally consider overly-nested conditions as code smell.

    if wrapper:
      ... 30 LOC ...
      if header:
        ... 30 LOC ...
      if body:
        ... 30 LOC ...



"... 30 LOC ..." followed by three or four more in the same logical chunk seems like the smell you should be worried about if fitting everything on one screen is the concern.


It's not about fitting things onto screen; it's about fitting things in brain.

If ~25 years of doing programming for money taught me something, it's that the code is written to be read and maintained by humans, and having really short, clean, one-purpose, composable functions makes your life easier both long-term and short-term.


Amen to that, friend :-) First thing on programming class in the eighties-nineties:

"Fit all functions on one screen."

At that time that was roughly 22 lines depending on editor used.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

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

Search: