The Pragmatic Craftsman :: Simplicity from complexity : by Stanley Kubasek ::

Assertions

Are you using them?

I only found out about them recently — they’ve been available since JDK 1.4. I think they’re vastly underutilized…. But they can be really helpful in debugging situations and don’t incur any performance hit.

You can enable them in your JDK by adding “-enableassertions” to default VM arguments (type “jre” in filters in Eclipse and edit it there).

Then in your code, whenever you have a feeling “this can never be null or false” add the assertion, as inassert thisField != null; and you’re done.

Assertions are a great debugging tool.

Related Posts

Favorite Quote

Topics

Tags

Archive

Currently Reading

Info

© 2001-2012 Stanley Kubasek About me :: Contact me

Me on Twitter

The key to performance is elegance, not battalions of special cases. — Jon Bentley and Doug McIlroy - 4 days agoThe ability to simplify means to eliminate the unnecessary so that the necessary may speak. — Hans Hoffmann - 9 days agoSo much complexity in software comes from trying to make one thing do two things. — Ryan Singer - 15 days agoGood code is short, simple, and symmetrical - the challenge is figuring out how to get there. — Sean Parent - 17 days agoSimplicity carried to the extreme becomes elegance. — Jon Frankli - 21 days ago

»see more

Recent Entries