Java is not Statically Typed (right now)

What?!?1?!/!? That is right, I said it Java is not statically typed and by proxy is not safer than dynamic languages. Zealots HALT! We can fix this, and I intend to add some gas to the fire that people like Bob Lee over at crazybob.org have started.

So let me start by saying this is the second version of this article. I completely scraped the first one for now, but it was basically a rant about how Java people are full of themselves for thinking that Java is safer than those dirty dynamic languages. The article was inspired because I have heard different people from both sides suggesting that Java is type safe and thus better to build on top of. Ola Bini wrote an article suggesting his language layer idea where he proposed that Java was currently the only viable solution for a stable layer. I happen to agree with Ola but only because I know Java can be that stable layer, but currently isn’t. The guys over at Software Engineering Radio are big Java junkies and I often get the impression that they feel it is a safer language.

The original post was a good way to get out my feelings, but it was horribly structured and not very productive (not that this post is much better). Fortunately one of my colleagues knew I was getting frustrated with this, and pointed me at a couple resources that might help with my frustration. One episode of The Java Posse was especially helpful, but not for the reason I think he intended. When he told me about the episode he told me it would be good to know what the other side might use as counterpoints to my complaints. Instead he directed me to the one Java developer who seems to have a passion for static typing. In this episode he was very vocal about how far he felt Java had moved away from static typing, and I agree with him on every point. Frameworks like Spring and Hibernate worked within the constraints of Java 1.4 and unfortunately that did not allow for static typing. The language itself made it impossible for these frameworks to be created with static typing, but that is not the case since Java 5 because of the additions of generics and annotations. Unfortunately we are on Java 6 now and these frameworks have not changed their approach.

Enter …Google? It seems Google has incubated a few projects that are brining type safety back to the Java language (note I said Java language I am setting up for an entirely different rant for later). Google Collections is the older of the two, and from what I understand is gaining popularity in the Java community. Brian has been talking about them for awhile and I usually just ignore him because I haven’t been interested in another collection API. The project owner of this project is co-owner of another great tool Google Guice.

Guice seems to be where Bob Lee spent a lot of time at Google although he has not moved onto android from what I can tell. Guice is a Dependency Injection Framework. Guice != Spring, instead Guice is what Spring started as. From what I can tell it does a great job at being a dependency injection framework and brining type safety back to Java. The greatest thing about Guice in my opinion is there is no XML! What?1!/?!?1? No XML how do you configure your application? Use Java! This is a whole other pet-peeve of mine (which will probably get an article very soon) and ColdFusion developers are the worst at it! XML is a great tool, but don’t use it just because you can! It was great for Java 1.4 because we didn’t have enough meta-programming facilities to configure our apps easily without it. But now with annotations and generics we can configure our code, using our code! What a novel idea to just write your code.

So there is hope, and because of projects like Guice I think the established frameworks are making changes. Spring 2.5 has implemented annotations like @Configurable and @Component spring is slowly removing the beans.xml file. At first I thought this was bad because, I believed the config file was used to be able to change things out without having to recompile the jar, but then I realized that was ridiculous and not a viable use case. I am not as familiar with Hibernate so I don’t know what steps they have taken to become more Java current, but I know iBatis has not taken many if any steps, as I they don’t even have generics for their SqlMapClient methods.

Does this mean I am now a Java fan boy and think dynamic languages are silly little toys that script kiddies use? Quite the contrary, I just have faith in the Java language. I was slowly giving up on Java, but now I realize their are passionate developers out there like Bob who want to bring Java back to it’s roots and give it frameworks that work within the language instead of around the language. I believe just like Ola Bini that their is a place in the development eco-system or both a static and a dynamic language, and over the next weeks I intend to describe where I think it would be best for these languages to live. As well as describe the advantages and disadvantages to each language type. Because as with everything else their is always a trade-off, there is almost never a perfect solution. I hope that my ramblings will help me and others understand those differences better so we can all become better developers.

This entry was posted in development, languages, programming, rant, software, theory and tagged , , , , , , , , , . Bookmark the permalink.

4 Responses to Java is not Statically Typed (right now)

Leave a Reply

Your email address will not be published.