Compiler checks are the best!
by Valentin Tolmer
From the article:
Have you ever run into this kind of comments?// IMPORTANT: Do not call this function before calling SetUp()!
Or checks like these:if (my_field_.empty()) abort();
Those are all symptoms of a (often light-weight) protocol that our code must respect. Or sometimes, you have an explicit protocol that you’re following, such as in the implementation of an SSL handshake or other business logic. Or maybe you have an explicit state machine in your code, with the transitions checked each time against a list of possible transitions.
Let’s have a look at how we can expressively handle these cases...