Skip to Content

Day 45: on safety

Posted on 3 mins read

In life, safety is a cozy feeling that gives you certainty but can get boring. I mean, having a safe job at a stable company can lack the adrenaline rushes of the startup environment. And like everything in life, there are those of us who enjoy a certain modicum of safety and those who just throw caution to the winds whenever they’re forced with a decision.

Unlike in life, safety in code is a must. A lot of the features that have been developed in programming languages throughout the years are aimed towards making the developer feel safe. Tests, types, optionals, try catch blocks, you name it, they all have the same thing in common.They want the person working on the code to feel safe. But what happens when these features turn on us and actually give us a feeling of uneasiness?

The scary tests

This happened last week. I had been working together with Uğurcan on a rest interface and everything was going fine. Until it struck me: all our tests passed, but they weren’t giving me the confidence I wanted. I think I spent about 4 hours trying to write our tests differently in order to feel safe and cozy again, but to no avail. In the end, I had to accept one thing:

Safety also comes from our mental model.

I realized our entire codebase was outside of our control, and we could only tests the things we were already testing, in the way they were being tested. What had to change was the way I was approaching the concept of safety in this particular domain. Since our code mostly consisted of communicating with the outside world, there was no way we could make sure everything would always work. No matter the amount of tests, that would remain a fact. So in our unit tests, we were stuck with just testing behaviours in made-up situations. And that’s fine.

I believe my problem resided in my difficulty to accept that fact. As long as the actual outside world behaved like one of our made-up cases, it would be fine and our real job was in creating valuable cases.

I see things a bit different now. It still makes me a bit anxious, but I’ve learned to cope with it and accept it.

In the end, it depends on how much safety one can actually get. We can easily fall into a loop and write massive amounts of unit tests in order to feel safer. But at one point, it’s an exercise with diminishing returns. There’s one point where the extra test doesn’t add enough in order to be worth it. The challenge is recognizing that point when we reach it, and not before.

comments powered by Disqus