Monday, May 11, 2009

Those wacky Java guys, and their Eclipse

How much did your company spend on Visual Studio.Net, just so you could write Asp.Net web applications? How much more did they spend if they decided to get the fancy "Team Systems" edition (which they'll pay an annual subscription renewal for next year)?

Then, you have to buy Resharper, because writing code without it is 35%* harder. I would say that without Resharper, code is 50%* harder, except that you have to keep turning it off when you go to edit markup because of performance issues (boo, JetBrains, boo. I know you can do better, I've seen TeamCity).

Now, why mention all of this? Because Eclipse does everything Resharper + Visual Studio.Net does, plus it makes Java not be (complete) poo. And its free. And it makes a great desert topping.

I've also been impressed with Spring, Hibernate, and Struts 2. Struts integrates Spring, allowing Struts to just use Spring to obtain objects, all behind the scenes without writing any code. Struts also integrates Dojo, a Javascript framework similar in function to JQuery. The Struts-Dojo integration reminds me of what Asp.Net Ajax was trying to do with UpdatePanels, only it actually works. Yeah, I said it.

To top it off, Spring is (unsurprisingly) easier to use in the Java world, as you don't have to specify assembly location or version to the Spring runtime...what with Java not having assemblies and all.

Hibernate now uses annotation (attributes in C#) based mapping, doing away with xml mapping files, and Eclipse allows you to generate your entities right off the database. Furthermore, Struts (God bless them), is not strictly typed, so there is no type casting done in the jsp markup, and no writing weird little helper functions to get around C# and Asp.Net's seeming lack of cohesion.

You know, stuff like this:

<asp:label runat="server" ID="SomesuchImportantLabel" value='<%# Convert.ToString(((DataEntity) container.DataItem).DomainDataItem.SomeDate) %>'/gt;


Would look like this in Struts:

<s:property value="DataEntity.SomeDate" />

Hey, Asp.Net and C# teams. You guys ever talk to each other about that whole Web Forms situation? It kinda sucks. Sorry to be rude about it, but VB.Net works seamlessly in Web Forms and with C# you have to do all that clunky casting. It'd be nice to leverage that slick "dynamic" behavior in the new C# language in Web Forms by default. It would put an end to all of that carpel-inducing cast-ification. Granted, your MVC stuff is MUCH better, and more comparable to Struts 2...I digress.

What's not to love? Err...well I did run into a few problems.

Eclipse's jsp editor has an irritating bug in it where it eventually just quits providing code completion, and pops up a dialog every time you press a key, telling all about this marvelous StackOverflowException that it discovered. Closing and reopening the jsp file fixes the problem, but it is disruptive, none-the-less.

Since Struts 2 isn't strictly typed, when you type in something incorrectly, it will just politely ignore it. This bit me mostly because I didn't expect it, given Asp.Net's ruler-to-the-hand response to typing things incorrectly.

Another thing that struck me was how easy it was to configure a JSP application. The web.xml file is tiny, and once you set it up, you can ignore it forever more. This as contrasted to how unbelievably annoying it was to try to find all of the dependencies for the technologies I was using. ClassNotFoundExceptions sent me to the internet more than once trying to scrounge up which jar file a particular class was hidden.

The last thing that slowed me down was not JavaEE, Tomcat, Eclipse, Struts, or JSP. It was the database server. Since I like making things harder than the should be, I decided to use a database server with which I have limited familiarity, PostgeSQL 8.3. Very good database. Except, the damned thing doesn't care for upper-cased letters (as I've noted before in another post). Placing escaped double-quotes into the JPA mapping annotations and explicitly defining catalog, schema, and name is a must if you use upper case characters and PostgreSQL, an issue I would never have encountered with MS SQL Server (it only gets pissy about spaces in object names).

The JPA development aspect in Eclipse isn't really astute enough to recognize the double-quote trick with PostgreSQL, and it gets upset when you put them in ('I don't know what this "Monkey" table is, you should have a Monkey table instead, I saw it on the DB.').

Despite the learning curve involved in switching from the .Net realm to Java, and indeed, most of my issues fall into the learning curve category, I wouldn't hesitate to suggest a survey mission into that world to any company trying to write a brand-new application or perform a serious (Web Forms to ASP.Net MVC) upgrade. Especially since Asp.Net MVC and Struts 2 are very competitive, feature-wise.

*Figures not to scale.



2 comments:

  1. I wrote a script once to find which class a jar file is in. It iterated through all the jar files in a folder and executed jar tf with grep. Maybe that would help you out some

    ReplyDelete
  2. That could be useful. I really wish the javadoc were a little more clear about what jars a class resides in, but its not like the .Net world, were a class lives (for the most part) in one and only one assembly. I suppose I could just toss all of my jars on the classpath and quit making User Libraries in Eclipse. Its pretty good about finding things if they're on the classpath, even if you haven't imported * from the package.

    ReplyDelete