Wednesday, September 24, 2008

Is My Method Too Long?

OK, here's a programming tip to help you know if your method you are writing is too long:

  • You find yourself writing comments that begin with "Step 1", "Step 2", etc. Especially when you reach "Step 14"...
  • Your method is over 150 lines long. Especially when it reaches 800 lines...
  • If you print out that one method and it fills more than 10 pages...
  • If it takes more than five minutes to scroll through it from beginning to end
  • If trying to follow the flow of execution makes you start fantasizing about joining Frodo and Sam on their trip to Mordor. Or envying Ulysses that short trip he made to get home after the Trojan war...
  • If there are more than 12 if blocks
  • If one of those if blocks contains 12 "else if" blocks
  • If there at least three places where it looks like the method might be ending, but then it keeps going and does something else.

No comments: