Tuesday, 30 October 2007

is struts that great?

People rave on about Struts and a lot of architects choose it for their technology stack, but I have to wonder why. J2EE already has a framework, it's called Servlets and JSPs. It uses a centralised file-based configuration (web.xml), and if people use it correctly, there's no reason why you can't use an MVC model for your application (i.e. apply some common sense and good practices). In fact, you could argue that Servlets and JSPs are just the "V" part of the MVC model, with Session Beans being the "C" part and Entity Beans being the "M" part.

Likewise Struts is the view part of the MVC model, you still have to code the control and model parts yourself. Actions are not the controller part, they are a the link between the view and the controller.

The reference article states the following advantages of Struts:
  • Centralized File-Based Configuration. Just like a regular J2EE application then, with it's web.xml.
  • Form Beans. Not exactly difficult to code up yourself and what Struts gives you doesn't really utilise a lot of re-use.
  • Bean Tags. OK, so struts gives you this tag library and a few other cool tag libraries, but they are trivial to implement and could easily be put in to a re-use library within your own company.
  • HTML Tags. Ditto.
  • Form Field Validation. Yeah OK, pretty useful, but have you seen the implementation? What a mess.
  • Consistent Approach. As I said in one of my earlier comments, you still have to code a lot of stuff yourself, consistent approach is about programming in a sensible fashion. Further more, templating engines (e.g. velocity) and MDA are becoming used more extensively, and these provide a consistent approach. Struts does not actually enforce any kind of consistency. The configuration is a mess and actions are simply Servlets with a different name.
So, I partially agree with a couple of the points, but I fully agree with all the disadvantages mentioned.

I really feel it is a waste of time getting up to speed with Struts. You're going to lose focus on real programming and become swamped by messy configuration and inappropriate framework code when there already exists a simple and effective framework in the form of Servlets and JSPs. The only good frameworks are the ones that encourage good programming practices and almost feel as though they are an extension of the language, or a filler of the gaps in the language. (Yes, of course I am talking about OSGi)

That all said, I have no experience with Struts2. Does the same spaghetti configuration exist? Are actions still bloated, glorified Servlets? To be honest, I can't even be bothered trying to find out!

In conclusion, Struts (like other bloated frameworks, read Hibernate) are a waste of time and just add unnecessary overhead and footprint to any project. Get back to basics and keep things simple. Think about re-use as you write your code and you will end up with a "framework" that works for you and your company, but don't go looking to create one!

1 comment:

Magicpete said...

I know that there is some zero-configuration option in Struts-2, but I've yet to try it out:

Struts 2 Zero-configuration
Results Annotation