Terminally Incoherent

Utterly random, incoherent and disjointed rants and ramblings...

Wednesday, October 12, 2005

The Joy of Java

Don't you love how Java can take a simple concept and make it unbelievably complex? For example take this simple comparison of C and Java code:


C Code:
printf("%10.2f", x);

Java Code:
java.text.NumberFormat formatter
= java.text.NumberFormat.getNumberInstance();
formatter.setMinimumFractionDigits(2);
formatter.setMaximumFractionDigits(2);
String s = formatter.format(x);
for (int i = s.length(); i < 10; i++)
System.out.print(' ');
System.out.print(s);


Now don't get me wrong - I'm not bashing Java. I'm a Java programmer at heart, but I do appreciate simplicity. Unfortunately Sun developers and Java Community sometimes seem to have a shady concept of the KISS principle.

I'm currently trying to find a good way to work with multispectral and hyperspectral images. I found that java.awt.image package does have some support for Raster images based on Multi-Band data which is great. That saves me allot of time developing data structures from scratch...

Only problem is that the creation of Raster image is one of the more convoluted, procedures in the Java language. First I will need to create a BandedSampleModel object, then use it to construct a DataBuffer which can be populated with my multi band data. Now the model and the buffer are not directly related in any way, but both are needed to create a Raster object. The sample model thing apparently is used to manipulate the buffer, but it does not associate with it directly.

The Raster object is also funky because instead of initializing it in a usual way (ie. via constructor) you need to build it using some static factory method which takes in the mode, the buffer and some other parameters. Just reading this stuff makes me dizzy... I hope I can find some sample code somewhere showing actual usage of this crap.

Java has this notion of hard separation between representation and data - you can see it all over the API. I think it makes allot of sense, but it needlessly complicates things and makes your head spin if you are not used to it. The real question is - is it worth to dig through this jumble to figure out a "popper java way" to do it, or would it be easier just to code from scratch? I personally think doing it the "proper way" whenever possible is a good thing, because it will result in a more standardized, robust and extensible code. And if I use standard Raster class, I probably won't have to worry about displaying it - I think a raster can be rendered automatically using the tools available in awt. I might be wrong though... But if they have a Raster, they should be able to display it, right?

Anyways, this thesis project might prove to be more challenging than I expected. Which is not a bad thing. I'm learning new stuff at least... I just wish I wasn't so swamped with other stuff and could spend more time on this.

0 Comments:

Post a Comment

<< Home