Unit Tests For Language-Learning

Feb 2017

I had a couple hours to play around with Clojure this week. Just how there are charities that are hundreds of times more effective than others (when applying some form of consequentialist calculation), there’s surely some methods of learning that are similar orders of magnitude more/less effective than others.

This post doesn’t attempt to provide a solution to the complicated question of how we quantify methods of learning’s efficacy, but rather is an outline of one approach I trialed that yielded promising results for me, viz. learning via writing unit tests.

At a high-level

Conceptually, I posit that this approach checks-out logically. The workflow is something like the following:

  • Conceive of single-purpose functions (ideally pure mathematical-esque functions; they’re deterministic and hence easier to test and their being void of side-effects prove beneficial when having to debug whilst learning).
  • For each function, assert the return of valid, expected output given input(s)
  • Work to implement the functions so that the tests pass.

Not only does this hone test-driven development skills, it also lays out clear steps for how to go from conceiving of a piece of code’s function to implementing it correctly - There’s a crystal-clear feedback loop from the tests’ results in a boolean value form (Either the tests past, or they don’t).

The probability that you understand how a correct implementation of a function works given that you’ve first defined the problem and them implemented a correct solution to make the tests pass, doesn’t quite equal 1.0, but it’s almost certainly much greater than the scenario that you make tests pass and don’t understand.