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 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)

  1. Maxim Porges says:

    Wow, you’re unnecessarily angry about this. Aren’t there whales being poached in the ocean, people dying in Darfur, or other causes better served by your unmitigated fury? :)

    With regard to XML config: “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.” That doesn’t sound accurate. Of course you can change an XML file without having to recompile anything, and there are totally viable use cases for this specifically IMO. I’ve seen a few in action.

    On a side note, I also agree that XML config is kind of a pain in the ass and I like the annotation-based config for many use cases, but on this point I’m not sure I agree with you (or maybe I just don’t understand what your exact point is).

    As for this one: “…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”. Assuming you are describing Spring, I’m not sure I agree with this either. If you ask me, Spring works around JEE APIs more than it works around the Java language itself. In fact, Java’s introspection capabilities and dynamic class instantiation facilitate Spring’s IoC model, so there’s a symbiotic relationship in there somewhere.

    *dons flame-retardant jodhpurs in preparation for response* :)

    – max

  2. Russ says:

    Good to see you haven’t given up on Java completely. As for the debate on static vs dynamic languages.. well I’ve always been of the opinion that each has their place, and trying to shoehorn one into the other’s role is silliness. I’m pretty ignorant on the virtues of ruby, but my reservations about it come mainly from hatred of the fan boy mentality. I’ll learn ruby eventually, but no one will convince me its the end all solution to every problem ever made. Its just another tool for another job.

    I definitely lean more towards the static language camp, and I think its because I hate runtime errors. When I say that, I mean the ones that come about because I mistyped something or got an object that wasn’t what I thought it was. I want the compiler to help with with that. I feel that was one of the reasons actionscript 3 became a little more strictly typed… flex 1 & 1.5 was just a train wreck, and its hard to find someone to disagree with that statement. The flex API still needs some fixing, but that’s another discussion.

    As for how hibernate is becoming more Java current, they are adapting the framework to use JPA annotations for the ORM mapping. Maybe Ibatis will do something similar, though it might look silly having annotations with your selects and inserts in them. Perhaps ibatis doesn’t lend itself to the JPA spec very well, but we’ll see. Maybe they’ll come up with their own spec. I know I seem like I’m a hibernate fan boy at times, but I’m just more familiar with it than ibatis. Hibernate is definitely in the same boat that spring was in that Java just didn’t provide the most natural way to accomplish its goal: annotations.

    Annotations are pretty exciting in general. There’s lots of potential on what can be tacked on to Java via annotations. We might even see a few convention over configuration frameworks come about. I personally would like to see junit 4 allow for a test method naming convention without having to extend junit 3’s testcase. Problem one of my misguided preferences, but you get my point. Also it’d be nice if jmock let you annotate member variables as mocks and it mocked them out for you.

    oh wait.. lookie lookie!

  3. Hi,

    why do you think we at SE Radio are Java Junkies?


  4. Daniel Roop says:

    I will start with the easy one…

    I apologize, thanks for dropping by. I by no means meant this as a bad thing, the fury of the rest of my post just kind o seeped out in a unintended attack on SER. What I meant was you are fans of the Java language. I thoroughly enjoy the episodes on Ruby and other dynamic languages you do, but it seems like the core crew are mostly Java developers. That is mostly what i meant by that comment.

    Also, while I have your attention. I want to let you know I am one of the people who subscribe to your feed, and do not participate in any of the polls etc. This is because i still haven’t caught up with the huge library of episodes you have produced. so usually by the time i get around to listening to the more recent episodes the poll is already over, or no longer relevant. As soon as I catch up I will attempt to provide you with feedback as your request in the episodes.

    Maybe that wasn’t the easy one…

    You are a Hibernate fan boy, but that isn’t a bad thing. I am a Ruby fan boy, it just means that we both have to take the time to look outside of our camps from time to time to make sure that we aren’t getting sucked into a cult mentality and are really doing what is best. It is great to hear that Hibernate is going to be adding (or has added) JPA annotations.

    As for iBatis, I don’t think the config files will go away, but I would like to see generics added atleast. So when you call sqlMapClient.queryForList, it is actually returning a List based on what I put in the config file.

    Annotations are exciting, and I didn’t really realize how exciting they were until recently. I can see a lot of power in them, combined with generics. Even though people complain about the syntax, the type safety and additional expressiveness it gives you is worth it. I didn’t mention it in my post but it actually got me thinking about how I could use the new facilities to create an ActiveRecord like framework, that was a little less heavy weight than Hibernate. The addition of generics more than Annotations help with this, because now my lists are typed, so I know the relationships between my object, and can build a dependency graph to do the insertions based on. Annotations would come in to override those default settings like table names etc…

    Yes I am overly angry.

    The reason why I say the use case for xml config is ridiculuous is because I don’t think those use cases are that common or necessary. I would be interested in knowing when you just changed a config file to fix something. Most of the time it would be a configuration settings, or updating to a new object (that you probably had to recompile your jar for). I could be wrong.

    My point about XML sucking, is more that, we should not default to XML any more. If we need it as a tool great. W3 describes XML as

    “Extensible Markup Language (XML) is a simple, very flexible text format derived from SGML (ISO 8879). Originally designed to meet the challenges of large-scale electronic publishing, XML is also playing an increasingly important role in the exchange of a wide variety of data on the Web and elsewhere.”

    I think the key words their are exchange of data. If we look at w3schools they use this definition:

    “XML was designed to transport and store data.”

    Transport to me implies a communication layer between systems. We could get into a debate about a config file being a communication between a developer and the system. But my point is this. XML was not designed to be a config file. That being said, just because a screwdriver was designed to screw … screws doesn’t mean it can’t pry open a paint can. I believe is XML works then we should use it, but now that we have generics and annotations that should be the first place of configuration. Work within the language not around it.

    On your point about Spring I agree. I am not complaining about what the framework does. I am complaining about how the framework does it. And it is no fault of spring. At the time Spring was created they didn’t have generics or annotations. My point is similar to my last, if their is a language construct to do what you want to do use it. Don’t create your own, unless you need to. And when spring was created they did, but now they need to become Java current. And to their credit they are, I just want to make it more visible, so more people understand why it is important.

    I didn’t expect such a quick response, thanks for the comments guys. I know my opinions are a little crazy right now, but my goal is to get conversation about these things. I think a lot of Java developers (not framework developers) have become complacent and don’t realize the tools they have to work with. I work with both of Russ and Max so I know that is not the case with either of you. Markcus, I don’t work with you so I don’t know if that is the case with you. But I know you are passionate about your work especially, MDSD.

    As anyone who reads my blog regularly knows I am a Ruby fan boy, and I am now seeing that Java can have some of the facilities that I know in love in Ruby. Not all of them can be there, but with some time and attention the barrier between the two can be broken down. I just hate to get into arguments like dynamic languages are slow, well Java used to be slow too, but with time and work they fixed that.

    Enough rambling from me, hope that cleared up some of the points.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>