Healthy Doubt of Your Code

Healthy Doubt of Your Code

One of the valuable skills of a senior software developer is to have an accurate amount of confidence in your code.

I used to frequently solve algorithm challenges like on the site Hackerrank. After a few years of doing these challenges I noticed something that always happened. I’d write a solution in 50-100 lines of code and be sure I had solved the problem correctly. I believed I had thought of every edge case, and I even stepped through every line of code meticulously. I would submit with confidence and find out the solution was wrong the first time. In fact I would normally miss at least a handful of edge cases or issues with my code.

Nowadays I am considering edge cases up front for every line of code that I write. I also have a gauge where I can sense when I am writing code “dangerously”, i.e. that the code likely has issues.

This has two really positive side effects for me. Firstly I am picking up a lot more edge cases up front because I am detecting them while I am in the context of that area of code. Secondly I am writing far simpler functions to avoid getting into that danger-zone. If I feel like I am hitting that low confidence point, I stop and refactor to something much simpler and that I feel I have more control of.

Hackerrank is a great tool to train yourself on this. In the real world unless you catch these issues yourself they will probably end up in production.

updated_at 30-10-2022