This exercise was developed as part of an Agile technical skills training class that we teach. For more details on this or other courses, contact us now. You are welcome to use these exercises yourself - more details here.

Clean Code with LEGO®


Demonstrate the value of keeping the code clean.


Teams should split their LEGO® bricks into two piles of equal size. Piles across teams should be close in size - we don't want one team with huge piles of bricks and other teams with few.

Step one

For one of the piles only, the team should "refactor" the bricks by sorting them in some way. Perhaps by colour or size or shape or any other criteria. Each team gets to pick their own way of sorting and in fact, the exercise works best if different teams sort by different criteria.

Put a time limit on the sorting activity. One or two minutes is generally good but if the piles are really large, more time can be given. If they run out of time for the sorting step then that's ok - in real-life, teams don't have an infinite amount of time to spend on keeping the code clean either.

Step two

For each pile individually, the team is to build a structure that contains exactly one of each type of brick in that pile. So a red 2x3 brick is different than a red 2x4 brick and a red 2x3 is different than a blue 2x3. Measure how long it takes to create each structure.

When done, each team will have two structures. Each will have exactly one of each kind of brick but the two structures do not have to look the same.


  • What did you notice? Any surprises?
  • Was one pile easier to work with than the other? What made it easier?
  • Compare the times it took to build each? Was one noticibly faster than the other? Which one?
  • If you factor in the time it took to originally sort the one pile, does that change your answers for the previous one?
  • Look around at the other teams. Did the way the bricks were sorted have a noticible impact on how easy they were to work with?
  • Not knowing what requirement is coming next, which pile would you prefer to work with?
  • Do you think that having more time for the sorting up front would have made a difference to the results?

Almost everyone says the sorted pile was better and easier to work with. How the bricks were sorted will have made no difference.