occasionally ranting about programming, tech and life

While back we had conversation over beer about testing and why each of us think testing is useful (or not) tool in programmers arsenal. Most seemed to think that biggest benefit you get from writing tests is that it makes modifying or refactoring code later easier, but I don’t actually buy it. If this would be the case it would be more preferable to actually write code first and tests afterwards, which from my experience never seems to work well. My reason to write tests before I write application logic is that I don’t need tests. That might need some explaining.

If you ask me, most important part of software is the architecture: that defines how easy extending software is, which in the end will determine how easy ‘finished’ project is to use and maintain. Thing that defines shape of the architecture is APIs and those are perilously hard to design beforehand because so many things affects how good APIs are built: creators experience, given language, external APIs that you need to use, already created internal APIs, good taste and most importantly problem domain in hand.

The last part is crucial because that makes it really hard to see if the API you are building is actually good before you start to use it and that point it is usually way too late to do anything about it (note: it doesn’t actually matter how API is implemented). Creating tests before we write any application logic forces us to think about API from viewpoint of using it and especially using it in current domain.

When you notice that you are sinking into garbage it is not too late to actually fix things because there isn’t going to be so much work to trash. And maybe there is no need for extensive refactoring later in the project.