Categories
geekiness Uncategorized

More on assertions

I posted on assertions this morning.

The rest of the day I spent writing and testing a class that is very central to my whole project and I tried to include assertions about all those “unvoiced” assumptions I was making about the code. To say it with Janet[1]

“Oh — my — God!”

Now that I consciously tried to think about what I was thinking while typing(what a reflexion!), I noticed how dangerous my code is. The combination of writing the unit test, using final wherever possible and including assertions wherever necessary makes the code much more solid and now somebody please prove it’s my error 😉

Of course my code is bigger now and doesn’t look as a sleek as c-code fresh from the obfuscator but I am sure my code has fewer bugs. All the funny things I found without having to think twice about what happened: infinite loops, switched parameters, missing “!” in boolean statements. All classics of mine …. work has rarely been as much fun as today – only: it takes forever to get anything done that way.

But *when* it is finally done, it is really done.

So my point? I’ll continue using assertions, that one is a sure thing. I even made one to guarantee an interesting loop invariant. Anyone remember how I hated invariants in 2nd semester[2] at university?

fn1. friends, chandler’s ex.

fn2. most of which I spent lying in the park instead of being in class.

By Yashima

Writer of code and stories

2 replies on “More on assertions”

Comments are closed.