Solving tic-tac-toe: an exploration of static vs dynamic typing

This talk explores how to write a TicTacToe API satisfying some interesting static typing constraints. Specifically, programs using the API may fail to compile depending on the state of play in the game, e.g. trying to call move() with an already completed game board. The real theme behind the talk is not so much in solving the TicTacToe problem but in pushing static typing to its limits (and some might argue beyond its useful limits - you will have to judge for yourself).

Various solutions to this problem are given using the Groovy programming language. The solutions range from very dynamic ones which only fail at runtime (and hence fail the original criteria) and rely on unit tests to gain confidence in their correct behavior through to several solutions which meet and exceed the problem criteria. Pointers to solutions of the problem in other languages are also given.

The API has several methods including move(), takeBack(), whoWon() which allow players to place moves onto a playing board. Programs using the API should fail compilation if players play out of turn, if takeBack is called on an empty board or if whoWon is called on a board still in play. This is a standard challenge that has been proposed to test the power of typing systems in various languages.


About the speaker

Paul King

Paul King

Paul King leads ASERT, an organization based in Brisbane, Australia which provides software development, training and mentoring services to customers wanting to embrace new technologies, harness best practices and innovate. He has been contributing to open source projects for nearly 20 years and is an active committer on numerous projects including Groovy. Paul speaks at international conferences, publishes in software magazines and journals, and is a co-author of Manning's best-seller: Groovy in Action.

More About Paul »