The Pragmatic Craftsman :: Simplicity from complexity ::

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.

Comments are closed.

Random Quote

Topics

Tags

Archive

Recent Entries

Currently Reading

Shelfari: Book reviews on your book blog

:: The Pragmatic Craftsman recommends

:: The Pragmatic Craftsman book reviews

Info

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

@PragCraftsman on Twitter

Which programming book has had the most influence on your career? I have to say "Code Complete" by McConnell - 5 hours agoI have not used Git myself, but see a lot of good buzz about it. Is this anology accurate: Git is to SVN as SVN is to CVS? #git #svn - 10 hours ago"Beauty of style and harmony and grace and good rhythm depends on simplicity." -Plato - 1 day ago