If you’re a programmer, you’ve probably told yourself or others “But this should work?!” or “This should never happen.” - maybe even countless times.

If you feel like this addresses you - that’s good! You’re making assumptions, which help you understand and scope problems. Without them, we would feel lost and it would make it much harder to learn new things.

Conclusion: assumptions are your friend, not your enemy.

Assertions

When programming, assumptions are special. We can assert them. Assertions are (sort of) our real-life equivalent of location-based reminders - but continuously. They allow you to challenge that assumption you just made every time the assumption is made, and let you know if your assumption was wrong (or not!).

Not only do they give you safety, peace of mind an confidence, but they also help sharing intent. Just like comments explaining why your code is written the way it is, assertions document your assumptions. To yourself, but also to others. And where you would have to read a comment (who does that?), assertions will be so friendly to give you a ping.


So next time you’re thinking “But this should work?!” or “This should never happen.” - or hear someone saying it - do yourself a favor and assert it. You will thank yourself (and others will thank you) later.

Assertions in programming are a privilege. We can check an assumption we’ve once made continuously and forever. Let that sink in for a second.