Friday, October 14, 2005

A taste of Java

I've spent the last few weeks reacquainting myself with Java. I've toyed with it a little over the last 7 years, but nothing serious. My job previous to Microsoft (so roughly 8 years ago...) involved working with Java, so this was not a virgin introduction. Besides, Java and C# are not really that different, syntactically. In fact, I've been surprised at how similar many of the utility libraries really are. Of course, I keep confusing my work-mates by calling things by their .Net name, rather than their Java name. It doesn't help that Java 1.5 added a whole new set of classes that are named just like the .Net equivalents.

Which gets me to my first point. What is with Vector and Hashtable being synchronized? I've been performance tuning our latest code and the Vector's synchronization overhead is huge! I understand the desire for correctness (synchronization) but the cost is so high for the majority of usages where that overhead is completely unnecessary. Now I understand why I've seen so many research papers on analyzing Java code to factor out synchronization where it is not actually needed. How about we just have a better class library? (Note: that doesn't mean that .Net is a good baseline either...) The solution? Add new classes! yay! Now half your code uses Vector and half uses ArrayList. sigh.

One huge factor in helping me jump back into java so quickly has been Eclipse. Aside from being slow, huge, and having key combinations that make me think more fondly of vi, this beast rocks. Intellisense is easy and fast. Background, incremental compile means that the basic development cycle of code/compile/test is fundamentally changed. Integrated JUnit means testing is easier than eating a jelly donut. The CVS integration is lovely, logical, and intuitive.

Some things I miss:

1) Version control with a concept of a checkin spanning multiple files (like Subversion). CVS is the industry standard, but I really miss being able to call up all the changes (spanning multiple files) that went into a checkin.

2) Good profiling tools. At Microsoft, I had access to some quite excellent internal profiling tools . It appears that most of the good java profiling tools are rather expensive. Thanks to the joys of classpaths and jars, I also find it rather tricky to get a good setup. The free tools I've tried are usable, but hardly optimal for medium or larger sized code-bases.

3) Struct! How I miss being able to define structures and arrays of structures. I can't believe that they implemented Generics (and I'm not a fan of how they did that either) and haven't addressed this huge deficiency. I want an array of structs, not an array of object references. The alternative makes me feel like I'm back programming in Basic; you allocate an array for each field of your struct, or you store everything in a giant Object array, and mix it all together.

Everything I've been working with is lower-level stuff, no UI, thus I can't really comment on the GUI libraries and since there is no .Net counterpart to what we are building, I can't comment on performance either. I'd love the time to port this whole thing to C# and compare performance...

One thing I really do like about Java is the wealth of options. There is such an incredible variety of libraries and tools out there, it is amazing. After being stuck in a Microsoft, Not Invented Here, culture for so long, it is wonderful to be free to benefit from such a community.

Actually, I think that the community aspect transcends Microsoft's NIH issues. Java has been around much longer, and is the language of choice for lots of people doing simple, cross-platform tools. This has created an ocean of interest that has turned into real code. Microsoft has never been good an encouraging such attitudes. People who build cool things on Microsoft's platforms are usually consultants who then sell what they build, rather than giving it away. On one hand, this means that some of the offerings for Java are less polished, but on the other hand, building on Microsoft's platform has a lot of hidden extra cost. All those tools and public code that you get for free with Java carries a huge advantage. There is a fundamentally different attitude in the user-bases of C# vs Java, that goes far beyond the language itself.