Code's Shadow
By Michael Renken
Nothing, in the presence of light, can exist without its shadow. When you finish a feature, you can not see it’s shadow. For this, you must shine your light on it by writing tests. In my mind, the tests themselves are the shadow. They’re the imperfect negative of your work that demonstrate its efficacy. As the work rises up against the sky, the shadow stretches across the ground even longer.
When I write tests, it’s usually the worst software that I’ve written. Each function usually has in-line the specific “set up” for the test, the “do something”, and the “assert that something happened” phases - each copy and pasted from the previous test and slightly modified to set up a different scenario and assert on the different output. It’s ugly. But, by contrast, the code itself looks good and is expected to function.
In learning a little about Carl Jung’s Shadow1, I eventually made the link between the moral effort of familiarizing yourself with your own shadow and with your code’s shadow via writing tests.
The shadow is a moral problem that challenges the whole ego-personality, for no one can become conscious of the shadow without considerable moral effort. To become conscious of it involves recognizing the dark aspects of the personality as present and real. This act is the essential condition for any kind of self-knowledge, and it therefore, as a rule, meets with considerable resistance. Indeed, self-knowledge as a psychotherapeutic measure frequently requires much painstaking work extending over a long period.
― Aion: Phenomenology of the Self published in The Portable Jung, edited by Joseph Campbell, Penguin Books, 1976, p. 145.
So, is writing tests moral? In a way, I’d consider it an honest effort. And there are also ways of writing tests dishonestly - re-writing the same functionality to test itself and potentially popagating the same phantom bug. So perhaps writing tests honestly could be considered moral as it does reflect your desire to ensure that your work holds up to scrutiny by demonstrating its functionality in very specific scenarios. I’d just be very careful when thinking that the tests themselves are the only moral effort as we still have to complete something useful that serves a purpose in a timely manner.
For now, I’m contented to know that my code exists enough to cast its own shadow - even if that shadow had to be tediously crafted. Perhaps if I spend enough time writing tests, I might learn more about my own shadow.
-
AROPA, Shadow - https://carl-jung.net/shadow.html ↩︎