- Write Code!
- Check with
- Contract with
assert's. And that's what this page is about.
An Inane Code Example
x = random.randint(0, 9)
y = 2 * x
#print("x: %i, y: %i" % (x, y))
assert(y/2==x), "This is the definition."
assert(y%2==0), "y should be even."
assert(type(y)==int), "Very Bad News!"
- Number Doubling Code
- Visual check that all is well with
- Make a lasting contract with
- Comment out
- Move On!
It's not production grade. But then, I am not writing production grade code. I am writing scripts.
And that's about what I had to say. For years, I had been using
assertas a built-in self-check, making it that much harder for me to break my own code.
Also, I think it's more elegant.