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

Shelfari: Book reviews on your book blog

:: The Pragmatic Craftsman recommends

:: The Pragmatic Craftsman book reviews

Info

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

Me on Twitter

@leszekgruchala Good to hear it's fast. Looking to upgrade to IntelliJ 11 soon. - 2 days agoPutting related classes together is another way of looking at "structuring your code by feature." Makes your code more cohesive. Big + imho - 11 days agoplanetgeek.ch » Structure your code by feature - http://t.co/KcpMBKVg (via @sociablesite) #sociable - 11 days agoTell Congress: Don’t censor the web! http://t.co/ZEkgOAW7 - 18 days agoI must admit, I'm one of those developers that doesn't know too much about WeakReferences in Java. http://t.co/HjW7v9e0 Time to change that. - 19 days ago

»see more

Recent Entries