More Evil
There are many areas of Java which are considered "evil" - static methods, as an example. In general terms, I do agree with the idea of avoiding such mechanism ("import static" anyone?) even going so far as to try to avoid singletons as much as possible.
However, I do wish to make a case for when using such things is not necessarily a bad thing. I lean towards the idea that such things are not inherently bad in isolated environments, where not even threading is something that needs to be considered. A good example of this is JUnit tests. They are isolated, self-contained, single-threaded little programs where readability is typically vastly more important than "correctness" of code.
We clearly see this in the way NetBeans makes use of JUnit 4 - by default the line "import static org.junit.Assert.*;" is in your newly generated source file. What this facilitates is that the actual test class no longer needs to extend "TestCase" (as was necessary under JUnit 3), but on a readability level, we will code "assertXXX" instead of "Assert.assertXXX".
Sometimes, "evil" really is necessary ...
Comments
Add comment
Comments for this post have been disabled.
Visit my Friends and Family
If you've enjoyed my site, please take a moment to visit my friends and family, many of whom have some interesting insights, and entertaining thoughts and ideas.
- Crause Family - the family website
- Peter Crause - my father
- Justin Crause - my brother
- Cencina Photomagic - great photographer
- Sophistica - hair design
There are no comments for this post.