Offensive Programming and a Preconditions helper

Pierre-Yves Ricau, a developer from Square, did a great talk on improving Android software quality: Crash Fast.

I recommend the whole presentation, but Offensive Programming part stuck with me (jump there).

You set your expectations about an argument or state, and raise an fatal exception if they're not met. Crash as soon as you can, so the problems doesn't trickle down the code and become harder to identify.

And since there are more tools for tracking crashes in Android, than for monitoring logs for warnings, bugs should get noticed and fixed quicker.

To help implement this in my current project, I made a small Preconditions class, based on a version from Google. Fell free to use and improve it.