Kool-Aid, drinking the

At work, I’ve finally had a chance to apply some of the practices I’ve been reading about (and advocating) for months. Foremost among them are the related concepts of test-driven development, (proper) unit testing, dependency injection and the principle of least knowledge (aka the Law of Demeter).

And what do you know: they actually work!

I’ve also wound up doing quite a bit of refactoring—mostly, as someone (maybe Michael Feathers?) put it, of “new legacy” code, stuff that’s been written in the last few months (not by me) which is full of global state and complex un-mockable setup. Most of that has been scattershot/mercenary work to make life easier for myself, rather than a concerted effort to rebuild the foundations without tearing down the walls, but I think I’ve made some incremental improvements that will help in the long run.

Now I just have to get the rest of the source control/build monkeys off my back. A few months ago I’d almost divested myself of one, through no small or short-lived effort, but just when I thought I was out….

2 thoughts on “Kool-Aid, drinking the”

  1. As much as dependency injection is a term that is thrown around a lot and comes off as a buzzword, it really is a better way to write code. Not only does it make code easier to test (and frankly, you should be writing the tests first), but using it helps you see just what you depend on. My rule of thumb is that if I am writing a method, I start with everything passed in as a parameter (even if it’s just conceptually) and pare it down a bit by either putting the method in an object that holds some of the state it requires or grouping the parameters together in some way.

Comments are closed.