January 11, 2011 1 Comment
Methods should be small. Ideally, they should hardly ever be 20 lines long. This forces the developer to create more methods that can shared and tested more easily. Smaller methods will also result in less unit tests for each method since there’s less logic applied.
Keeping method small also helps to enforce the concept that methods should only do one thing. The more logic that exists in a method will likely limit it’s ability to be shared and reused. It also ensures that changes to the method will only affect the single purpose of the method.
One level of abstraction per method is also a good rule to follow. This helps others understand what the method is doing which prevents bugs from getting into the software.
Following the above tips will result in more methods, but it doesn’t necessarily result in more code since methods can be shared more easily.