TDD, whatever that means.
Thoughts that fell into my head while watching the talk on friday.
If you didn’t know already, David Heinemeier Hansson, Kent Beck and Martin Fowler hosted a talk about Test Driven Development this past friday. I strongly suggest watching it, but if you haven’t got 30 minutes to spare however, feel free to peruse my mind-blowing thoughts about the talk instead.
So, apparently, TDD came about because Kent Beck read about it in a book when he was 10. No, really. Still, regardless of its origins, there’s no denying that TDD has been widely popular (perhaps to a fault, which is what sparked this talk in the first place), indicating that many developers enjoy the workflow it encourages (or are just afraid of doing anything else, because this is the right way to do something).
I want to really emphasise the semantics of that last sentence. Beck explains that he really enjoys the workflow of writing tests first and then the accompanying code, due to his personality.
“Lame! This is going to be another ‘whatever works for you might not work for everyone else’-opinion,” you might think at this point. Fuck you, you’re only half right.
Wait, you wanted what?
At one point, Kent states that he “tends to get overwhelmed by big, complex problems”. Sound familiar? I think that’s a common problem for any developer (‘Hey, create a Facebook clone for us. Also, can you make it better?’) — complex problems (in any discipline, really) need to be broken down in order to seem surmountable.
So, what has this got to do with TDD? Kent said that “Even if I don’t know how to implement something, I almost always know how to write a test for it.” So for Kent Beck, TDD goes hand in hand with disassembling complex problems — it’s more of a way to approach a certain situation rather than a dogmatic approach he always adheres to.
I think that’s important: Kent Beck uses TDD in his approach to break down complex problems because he fucking feels like it, and that doesn’t mean that you necessarily do too.
For instance, David says that even though he understands how Beck reaches his conclusion of ‘at least I can write a test for it’, he does not feel the same way about development at all. His approach of disassembly consists of writing code rather than tests first, and you have to give it to the man — it seems to be working.
Get Nicolay Hvidsten’s stories in your inbox
Join Medium for free to get updates from this writer.
I feel the following quote from Kent captures the differences of his and David’s approaches very well.
“TDD is one way (of feeling confident that the code does what you think it does), but there’s lots of other ways.”
That doesn’t go there, brah.
So, while the benefits of TDD might be more dependant upon your personal preferences rather than a universal truth established by some programming deity wearing an ironic t-shirt, one thing all three participants agreed upon was that there were definitively certain scenarios more suited to TDD than others.
A common approach to remedy this problem (i.e. isolating components of code) is to use mocking, something which David is a big opponent of. His point being that if you mock everything, then you’re not really testing anything worthwhile.
Regardless of his views, mocking is very common in TDD environments and surprisingly enough (at least to me), both Martin and Kent agreed with David on this point — stating that neither of them usually employed mocking, as this felt like a way to shoehorn a problem to fit with TDD.
Martin and Kent went on to say that while they enjoy the TDD process and the short feedback-loop, they had both recently encountered problems where they couldn’t utilise it — for instance when you don’t know the user input — which does lend credence to the idea that TDD is not something that fits every situation.
You want to be sure that Random Insulting Statement bot you made works with the given input? TDD the hell out of that shit. However, it might be an idea to take a different approach if you want to test how your bot interfaces with that tumblr feed of overweight people wearing fedoras.
Don’t worry, be that other thing.
During the talk, David brought up a concept which in my opinion is the single most important point of the entire debate: programming happiness. An important facet of which is that there are different ways of achieving it, TDD being one.
Apparently, differently styles work for different kinds of people (hold the press!), and TDD is just one style, which can be applied in a variety of different ways.
Want to unit test the shit out of everything, refactoring your code (and tests) as things become more complicated? Go the fuck ahead! Maybe you prefer writing high-level acceptance tests, testing the whole shebang of the functionality you’re implementing — touching (perhaps) a view, a controller, some helper classes and hell, even the database before writing your code? Knock yourself the fuck out!
Want to write the entire functionality up front, and then start testing it? Go for it, just beware that you’ll be the ugly duckling of the office for a while.
In the end, to me anyway, TDD is just a tool — albeit a valuable one. What really matters is what makes you, much like the vampire known as Pharrel would have it, happy. Programming happiness > TDD any day of the week, but for many people this inequality might, in fact, be an equality.
Even if you are one of those people who really enjoy writing your tests before you write your code, it might be an idea to keep in mind that it’s not necessarily suited for every scenario — so don’t give yourself too hard of a time if you happen to print ‘Hello world’ before writing ‘console.should.contain’, just chill out and have a beer instead.
A final point on which there was full agreement was that a piece of functionality is not done until both the code and tests have been written, something which isn’t exactly a world shattering opinion. I mean, if you disagree with this statement, you’re probably not reading this — in which case it’s safe for me to say that I think you’re an idiot.








