Clean Code Tips #1-3: Methods Should be Small, Do Only 1 Thing, and 1 Level of Abstraction
January 11, 2011 2 Comments
#1: 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.
#2: 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.
#3: 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.
Pingback: Clean Code Tips #4-6: Method Arguments « It's a Digital Life
Loving the blog thanks for the information.