Archive for June, 2007|Monthly archive page

Reified generics possible in Java?

The generic implementation is problematic: with the erasure of the generic type information, a instance of type ArrayList<String> is equivalent toArrayList<Long>, basically both runtime instances have the type ArrayList. This allows useful constructs like <?>, but the original generic type is lost at runtime. Since Java 5 I’ve found no way to get the type information back, the “erasuring” seems to be final. But today I’ve found a interesting article at Artima.com, which tells otherwise: Java keeps track of the type information in subclasses! It is possible, with a little bit of utility code, to get back generic argument of the parent class. So you can write a abstract factory class, create a subclass and use it to create instances of this type. This is for my part one of the most missed features I’ve in other languages such as C#.
The article also has a second interesting snippet of code, a version of anonymous sub-classing which is at least uncommon (and easy to recognize).
TypeAwareArrayList<String> stringList = new TypeAwareArrayList<String>(){}; actually builds a anonymous class based on the type of the abstract parent class (see more in the article).

We have to wait (hopefully) for Java 7 to get rid of the erasures, but this article shows a practical way for some of the most missed idioms we have lost.

Release It!

Michael T. Nygard’s book is one a rare one because it tells something about the time after a project was finished and is released for the first time into the world. The basic message is that you can not anticipate failures which certainly will occure if the system is used. Besides failures caused by programming failures, a lot of failures occure because the capicity of the system was never tested and the constraints of it indifferent situations were not correctly identified. He presents patterns and anti patterns for stability and capacity. Some are well known, but often not easy to handle (e.g. resource pooling), others are interesting as the circuit breaker which has the purpose to “break” the normal handling of operations if the failure rate becomes to high. After it has “opened”, all calls will fail immediately, but all ongoing transactions can be completed and the resources can recover, so no cascading failure happens. Another favorite is that we have always the wrong intuition about scaling, we always think linear, so as example I’ve clearly underestimated the change of database size from 100 GB to 1 TB and 2TB and so on.

So QA and load tests are not needless, far from it, but you should expect that the only accurate model of the world is the world itself. Building script able management interfaces, decouple systems as much as possible and expect that users will do unspeakable things will help. With the time and accurate data about the system’s health, it will become more predictable.

The book is a bit web site centric, but nearly all is true for all large system deployments. It covers a lot of points in very few pages but this can be a advantage because it is fast to read and will certainly help to smooth deployment and troubleshooting in operations.

Interesting interpretation of Sūnzǐ bīngfǎ, The Art of War

Sūn Zǐ has written the Sūnzǐ bīngfǎ nearly twenty five centuries ago, but it remains a valuable source of ideas not only for military strategies but it is also very applicable to behavior in modern economy. What makes it valuable today is that you should avoid confrontation at all costs, but if you have to fight for your targets, be prepared and think before you move.
Software development encounters very often the same situation as described by
Sūn Zǐ, but recommendations are not directly applicable. So Bruce F. Webster has written the book The Art of ‘Ware years ago and the second version is now in work. The interpretation of the core tenets are very well interpreted for our modern times and provide very interesting ideas how to behave in the uncertain terrain of software development or -markets. You may have heard some ideas in other forms elsewhere, but this version maps all thirteen tenets to our everyday problems and is written in the compact style of the original work. The draft is available in public for three.

Americans are very fascinated by Sūn Zǐ so no wonder they try to interpret the original work in a lot of fields. But a lot of his original tenets seem to be a strong meme and at least this version I’ve found interesting to read.