On the plane tonight (I'm in Redmond this week) I got to thinking about writing "Maintainable Code" and what it means in light of our fad-centric industry which churns itself every 18 months or so with a new language or platform version. We all inherit projects and are confronted with Geek Lust to rewrite everything in our own image - but what is the motivator for you when you do this?
Monday, January 21, 2008
Rob, will there be a testing story for the Repositories? That is. how would I go about mocking them out for unit tests so as to avoid hitting the db?It's a good question. My reply wasn't so professional:
@Steve: if you like TDD so much why don't you just marry it :pYou have to understand that I love Steve. No, I LERRRV Steve. In fact I love him so much I stole him from right out of Haack's nose and made him a main committer for the new SubSonic MVC stuff (Steve is Phil's right-hand with SubText). Booya! Anyway - I made sure to follow up the conversation with Steve on Skype to get his ideas, and I asked him what he thought we should do to make some of our new stuff more testable (we have a whole mess of non-virtual, non-interfacable static methods as part of our Data Factory which are not easy to test). He came up with a great plan (paraphrased, geekiness his):
You could crank up an IoC containter and use Dependency Injection...My reply was my usual not-so-professional-smart-assiness:
Ooooh! I like that idea! And look at all the buzzwords I can blog about!I hope you don't read this as me being snarky - I couldn't help myself. Steve is such a good guy and he's shown me some great tricks regarding TDD and tools. But see, when you're nice to me, my claws come out and I rip your best shirt while coughing up stuff on your best shoes. I can't help it... it's my nature. When Do You Tell A Client To Rewrite? So as I sit there tonight on my plane, watching a Horrible Movie with The Rock dressed up as a cheerleader, I got to thinking about Steve and our conversation (Steve used to be in Glee Club and on his highschool Drill Team). Unit Testing is something you learn about in school, but let's face it - no one in the MS space took it seriously until NUnit came out a few years back - it's a "wave" that's hitting it's stride right now (and a very good wave it is) and I'm wondering just how many people will rewrite an old application to be more testable? Even in the case where one might be working just fine? If you were handed an ASP Classic site (yes, there are many) - let's say ... ohhh... Starbucks - would you push them to rewrite it? If so, would a complete set of Unit Tests be part of the cost? A client said to me once (over beers):
It doesn't matter how good the developer tools get, you guys will always find ways to invent work to fill your time and bill me for it.Interesting point and, from a client's perspective, hard to argue with. I didn't tell him I needed Unit Tests 5 years ago - why are they so critical now? Again: I'm not criticizing TDD or Unit Testing. Just using it as an example of something that wasn't commonly done just a few years back. Honestly - please don't flame me :). I love Unit Testing. It loves me too. I think. Anyway... When do you council a client on a rewrite? What sorts of issues come into the conversation in terms of cost/benefit? Have rewrites worked for you and has your client been happy? I'd really appreciate your feedback on this...