Saturday, September 24, 2005

On JSF, Struts, & Spring

I started a new contract yesterday and got a bit of a taste of what to expect in the coming months. We're building web-based Java applications and the typical J2EE MVC, Facade, DAO, & (evil) DTO patterns are in full effect.

I'm fortunate enough to get to continue to use Hibernate for ORM which is very cool. I still think Hibernate and object relational mapping in general is a very good thing. The biggest "problem" I see is that it looks like people are opting to use the "TopLink" way of doing things by using Criteria objects instead of HQL. What are they thinking? Why anyone would choose to use a non expressive bunch of Java code to write a query is beyond me. HQL is way better and one of the reason I like Hibernate so much better than TopLink. I e-mailed my supervisor about this one and we'll see what kind of response I get.

On the web framework front, we're using JSF (MyFaces specifically) instead of the defacto standard Struts. While fundamentally I don't have anything against Java Server Faces (it does have some nice features) I have to wonder why they made the decision to use it. David Geary (co-author of the book "Core Java Server Faces") once gave a talk at our local Java User Group meeting once and said something to the effect that "JSF was a standardized Struts that IDE vendors could rally around to create JSP visual editing tools". Part of that goal was to compete with ASP.NET. Coding up JSP pages is a bit mundane and who wouldn't rather have a tool write that junk for you? Well apparently the people where I'm working made that decision! It's still all hand-coded. So now we're using a framework nobody understands and I suspect productivity is lower. Where's the logic in that?

MyFaces seems very similar to Struts so conceptually it's easy to grasp but it's the details and the peculiarities of how things work that slow you down. It also seems to be at a higher level abstraction from the lower level request/response and the HTML it generates (the theory is that you can generate something other than HTML). But I think I prefer Tapestry's idea of staying close to HTML and only injecting the dynamic content. Tapestry allows you to use any HTML editing tool and HTML is well understood. JSF on the other hand is this parallel universe of tags that look a bit like HTML but can only be edited in a text editor or a JSF visual editing tool and at the moment there doesn't seem to be any tools that play nice with the MyFaces implementation. Secondly, staying close to HTML allows you to take advantage of advances in HTML like XHTML and AJAX. JSF, like ASP.NET, gives you a component model that will likely adapt to support advances in the underlying technology but there will always be a time lag. Perhaps the other minor benefits will outweigh the losses. We'll see... Right now it looks like change for the sake of change.

They also bought into the whole Spring IoC (a.k.a., Dependency Injection) idea. At first glance this seems like a good idea. You design to interfaces in an attempt to hide implementation details. Theoretically it should enable unit testing and allow us to switch between POJOs, Web Services and EJBs with greater ease. Of course it comes at a cost of greater complexity for questionable gain. For example if you create a DAO interface and then only ever create one implementation of that interface what have you gained? And then you have all the XML gunk to wire everything together. Theoretically, a meta data approach to wiring stuff together is better but not having experienced it before I'm a bit skeptical. The fortunate part about Spring is that they seem to understand that they need to play nice in a bigger community and support all the major Java frameworks out there so integration looks to be pretty straightforward.

My feelings are a bit mixed... Sometimes I believe that the dynamic, competitive, multi-vendor Java community is more vibrant than the MS .NET community and that the variety of tools is our attempt to find the most effective method for developing software. But sometimes I believe that we're all just chasing the next trend and running around in circles and I envy the single voice (Borg like as it may be) leading MS development. Anyway, I have some things to learn and I'll withold my final judgement until I've been using JSF and Spring for awhile. Maybe there are some pleasant surprises to come.

No comments: