Search code examples
tddgame-engine

Trying to use TDD when unfamiliar with the domain your programming in


Background:

I'm currently creating my first game engine project for learning purposes. This is the first larger project I've ever done. I knew going in to the project the sort of higher level details of what's involved in a game engine (such as separate systems - input, graphics, audio, physics, etc.) but when getting into the nitty gritty I'm kindof figuring things out as I go. My coding process right now looks like this:

1.) Figure out some quick, higher level details of the system I want to design

2.) Start some experimental coding to see how exactly things need to work

3.) Add tests afterwards once I'm feeling good about what I have.

Since I'm pretty unfamiliar with the problem domain (game engine programming) I find I really need to experiment in code to see what functions I need and what design suites best. However, I know most of the community (so it seems anyway) usually advocates more of a TDD approaches to building applications. I can see the benefit of this but I'm not quite sure how I would apply the "Write test first, fail, then pass" when I'm not really even sure what functions I really need to be testing yet. Even if I can think of 1 or 2 definite functions, what if during the experimenting phase I find it's better to split those functions out into more functions across different classes. Then I would have to redesign both my code and my tests constantly.

My Issue/Question(s):

So, is there a good way to go about using a TDD approach when your experimenting in code? Or is TDD generally meant for those who are familiar with the projects their working on, and have an idea of what the design needs to be or what functions they will be needing to test?


Solution

  • A common approach when using TDD in unfamiliar territory:

    • Do some experimental coding to learn more
    • Set aside the experimental code and start the TDD "test first" approach
    • As you write production code to make your tests pass, you'll be harvesting pieces of your experimental code.

    The benefit of this approach is that with the TDD "red,green,refactor" cycle, you'll usually be improving the design of your experimental code. Without it, your experimental code can often end up as a "big ball of mud".