Smaller is better; Keep your functions short

Last modified: January 9, 2009 - 10:00

If the entire function implementation doesn't fit on a single screen of your editor, it's probably trying to do too many things and should be split into smaller pieces.

  • If it all fits on a single screen, it's more likely that everyone will be able to actually comprehend what the function is trying to do (and debug if something is going wrong).
  • Smaller functions that only do one thing are easier to write unit tests for.
  • Smaller functions that only do one thing are more likely to be reusable.
 
 

Drupal is a registered trademark of Dries Buytaert.