We’ve been working on the trivia codebase. First impression: This day was gonna be way too easy because the codebase just doesn’t present my biggest struggle with legacy code: it’s too much to memorize, you never know where to start with a certain bug.
Thank god, I was wrong about that as I underestimated the complexity of the code. I really adore their authors: how they rendered so many gotchas into so few lines. Really, achieving this density of bugs is an art. Also, a good way to raise my maybe-not-so-pragmatic paranoia. If you’re interested, clone the code, read it and try to fix one of the bugs you find.
So, what did we do there during those sessions and retrospectives? We:
– added end-to-end testing
– added feature-specific tests for new features
– practiced SOLID principles
– debated a lot about the “right” way of development vs the rambo fix. (Reminder to myself: a coderetreat is not about rambo.)
My first gotcha was that you just cannot go and fix/refactor legacy code because you just don’t know if there is a dependency on a certain bug (e.g. a typo in the log).
Then, I learned that when working with hard-to-test code it’s ugly but fucking effective to write white-box tests. It’s always a trade-off between test-code independency and the time you spend with the code. When you know that you’re gonna have to refactor your API anyway, then a temporary test is better be written quickly.
Finally, I learned a lot about big, end-to-end tests. You know the sort of test which when fails only tells you that “Oooops, something went wrong”. They are way more useful than I thought: they provide a good basis for refactoring as changing the code structure without changing the behavior. Also, you better be able to automatically regenerate them after each change you make otherwise you’ll never make any change in the behavior – ‘cos you know, you’d loose these tests. This means that you need some sort of test runner which you can automatically feed with input – expected output pairs.
Last but not least: it was amazing to meet so many committed and talented professionals. I had not only a useful, but really nice time too. Thanks again to Athos, Devil and Emarsys!