The Transformation Priority Premise


When following Test-driven development (TDD), you will make changes to your code. These operations that change the behavior of your code are called transformations. Transformations can be used to pass failing tests (for example, returning a constant to get a test to pass).

  • (nil → constant)
  • (constant → constant+) a simple constant to a more complex constant
  • (constant → scalar) replacing a constant with a variable or an argument
  • (statement → statements) adding more unconditional statements
  • (unconditional → if) splitting the execution path
  • (scalar → array)
  • (array → container)
  • (statement → recursion)
  • (if → while)
  • (expression → function) replacing an expression with a function or algorithm
  • (variable → assignment) replacing the value of a variable

TPP in Action: Minimax Algorithm

I recently was tasked with performing a kata, showing how I implemented the minimax algorithm in a Tic Tac Toe (TTT) app I wrote. I already had the algorithm ready and working, and all I had to do was to retrace the steps I took to build it out, and then practice them to be ready for the presentation.

Recursion, one step at a time

Just as a point of reference, here is the complete Minimax class:

Figure 1: Complete Minimax implementation.
Figure 2: Minimax method gets the score based on the player that just went, and returns it.
Figure 3: Added in IF statement, to return an invalid move if the game is finished, or the next possible move.
Figure 4: Added unconditional statements to update current_score.
Figure 5: More unconditional statements, all to pick the best move from possible_moves.
Figure 6: Adding recursive call to switch between players.


One of my key takeaways from learning about and applying the TPP is that it really can make the difference between being able to implement something, and not being able to implement it. This might seem obvious, but I spent a while examining my initial minimax implementation, not really having a clue where or how to start. Using TPP I was able to find a starting point, then take small, methodical steps to work towards the final solution. This improved my test suite as well, making each test cover just a small piece of functionality.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store