Short Methods and Small Classes

If you’re used to writing & reading long methods, dealing with small methods & classes can take some time to get familiar with. Keith Ray has a great writeup on Reading Short Methods and Small Classes.
He also cites Jerry Weinberg’s great test to determine if a function/method is too long:

  1. Pick a function.
  2. Understand it, what it’s supposed to do, how that is accomplished.
  3. Memorize the function.
  4. Then, without looking at the original code, write the function from memory.
  5. If you’ve made a mistake, the function was too long, or otherwise too complex.

Comments are closed.