Today, I’ve listened to the two podcasts that have been spawning cries of “heresey” and “zealot” from around the net. Those are of course the Hanselminutes interview of Uncle Bob and Stack Overflow Poscast #38. These have stirred up a lot of commentary regarding S.O.L.I.D principles, Star Trek races, semantics, geology and construction and some general ranting. Needless to say, I’ve enjoyed it a great deal. It’s great to see so many people in the .NET and the developer community at large getting so passionate and vocal about these topics.
Before I go on any further, I would like to say that I very much enjoyed reading Uncle Bob’s book Agile Software Development, Principles, Patterns and Practices. It is one of the better technical books I’ve read. So I have a great deal of respect for the man, he knows his stuff. Personally, I would never say that he “doesn’t code very much”, unless I was being sensational. Doing so would be both unprofessional and hypocritical on my part.
Apart from that, what seems to be under fire is how frequently to use SOLID principles, best practices, etc. Are you, as a developer, being a greater asset by simply hacking out a solution of trivial to moderate complexity in the shortest amount of time, or are you a greater asset by remaining disciplined and sticking to SOLID principles most, if not all, of the time.
Underneath it all, there is an interesting question asked here. One that I have struggled with and I am reasonably certain that you have too.
How much should you test, abstract and otherwise follow proven best coding practices?
- When Bob says that each consumer of a service should have it’s own interface to it, does he really mean every consumer? Isn’t that wasteful?
- When your programming mentor mentions that you really shouldn’t write any code that doesn’t fix a failing test, does he really mean that all production code typed in should be the minimal possible to pass a test? Does he realize how much test code that is?
- When adhering to SOLID principles should you really confine all new keywords to your factories and place everything in your IoC container(s)? Seriously? Even the boring little classes?
I’m sure you have answers to all of these questions. I’m also fairly certain that you could add at least a couple more questions to this list. Regardless, I think that these are reasonable questions to ask. Ones that every developer asks themselves at some point or other.
Of course, with these and so many other difficult and somewhat abstract questions there is no simple black or white answer. My answer is “It depends.”
To answer these questions you will more than likely have to ask yourself a series of other questions. Some of these may include:
- What is the worst thing that will happen if this system blows up at any given time?
- How will my actions affect developers (myself or otherwise) working with my code in the future?
- What is the return of my investment of time, if I follow what I believe to be the best practices?
- Do I know enough about this topic at all to make informed decisions at all?
- If I follow what I perceive to be best practices against my “other (better?) judgement”, how likely am I remain disciplined on this project?
I’m sure there are a number of others that you see missing from this list as well. What it boils down to, is that we want to produce great or perhaps simply good software in a timely manner, and enjoy it. If this wasn’t the case, you wouldn’t care about practices, principles or pineapples. The question isn’t if SOLID principles have their place, it is, “is this their place?” It’s not a question of do I want quality, it’s “am I willing to go to this extent, when I don’t see a benefit?” None of us like to write more code than necessary to achieve our goals. Writing excess code can be frustrating. So can learning. But learning is what we are doing. Your gut instincts as to what is or is not excessive use of principles and practices will likely change over time. I can’t say if you will use them more or less with experience, but looking at the credentials of the folks out there teaching us, my guess is that you will find yourself using them more.
Follow as many best practices as you can maintain both your discipline and your enjoyment with. After a little time, re-evaluate. If something isn’t working out, tweak it. If something is turning out to be a good thing, try adding some more. This isn’t a formula driven profession and no two people will be happy coding in exactly the same way. Use your best judgement, and remember that we don’t know everything, yet.