6 ms·
I use assertions heavily in my own code and they work extremely well. I don't buy the distinction between assertions and invariants as made in the blog post th
by _a_a_a_ 3y ago
I use assertions heavily in my own code and they work extremely well.
I don't buy the distinction between assertions and invariants as made in the blog post though, as if one was a higher level variety of the other. You can assert anything (though it may get expensive!). I consider invariants to be the logical statement of what should be true, and an assertion to be a program statement that actually performs the check.
Terminology, terminology, it doesn't matter. I agree with the author, it's an incredibly valuable tool.
- tracnar 3y agoHe later in the post shows invariants which cannot be verified as assertions within the system (e.g. as a process within a distributed application), because they rely on having an omniscient view of the system (e.g. access the state of all processes in the distributed system at one point in time). I think that's where the distinction makes sense. Of course you'll likely still turn those invariants into assertions, but in some kind of simulator which can view the complete state of the system rather than in the system itself.
- _a_a_a_ 3y agoAh, yes, thanks
- convolvatron 3y agono, its doesn't. but to me an invariant is something that might be useful in a static context (that is something a compiler might enforce, or use to generate more efficient code), and an assertion is a runtime construct.