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

Keeping your procedure short still has value, even if they just do one thing after another, and are only used once.

That's because separating them out into separate procedures enforces a simple interface: communication only happens via arguments and return values.

When a reader sees a block like

    DoAll() {
      // A
      ...
      // B
      ...
      // C
      ...
    }
then they have to manually verify that the variables in A don't interfere with what's happening in B or C. (Either accidentally or by design.)

In C-style languages you can use {}-delineated blocks to get most of this benefit of the short-method style in the long-method style.

In eg Python you can use nested functions to achieve your readability goals of not having to jump around while still keeping your state from interacting.



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

Search: