If you’ve never done Test Driven Development or aren’t even sure what this "crazy TDD stuff” is all about than this is the series for you. Over the next 30 days this series of posts take you from “I can spell TDD” to being able to consider yourself a “functional” TDD developer. Of course TDD is a very deep topic and truly mastering it will take quite a bit of time, but the rewards are well worth it. Along the way I’ll be showing you how tools like JustCode and JustMock can help you in your practice of TDD.
Previous Posts in this Series: 30 Days of TDD – Day 27 – Reader Question #3
Robert Pack asks
I noticed from the first installment of the series that you say you write classes and methods so that they only just pass tests and no more, cutting down on dead code and zombie bugs. Where does this fit into some peoples’ rules for methods having a maximum number of lines etc? Do you think that’s a completely unrealistic limit to place on methods and that they will be as long as they have to be or do you subscribe to keeping methods below a certain size? I’m interested to hear your thoughts on this.
Thanks for the question Robert.
Personally I’m not in favor or any arbitrary limits or requirements on class or method size, other than I try to keep them as short as possible. I think a method should be only as long as it needs to be to do its job, but to try to assign a number to that would be impossible as every situation is different and I would rather have developers thinking in terms of efficient, readable and maintainable code as opposed to a metric.
Instead of focusing on arbitrary numbers I prefer to focus on things like adherence to the Single Responsibility Principal. I’ve talked about SRP many times in this series and am a big believer in it’s ability to turn nasty spaghetti code into code that is easier to maintain and reuse. Keeping your code compartmentalized by function and making sure that each method or class has only one reason to change or function will go much farther to keeping your code in good shape than a meaningless metric.
Hope this helps.
Continue the TDD journey:
Subscribe to be the first to get our expert-written articles and tutorials for developers!
All fields are required