Community Documentation

Smaller is better; Keep your functions short

Last updated January 9, 2009. Created by mr.baileys on August 23, 2008.
Edited by Senpai. Log in to edit this page.

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.