Tuesday, March 3, 2009

Symfony VS Struts in Java

Alvaro has a very nice article about symfony performance and features. I just commented over it. it is a bit long, so i leave a copy here.

This article is about Symfony in php and Struts in Java. (they are compared in the same order that Alvaro did in his article. )

compared with struts(the mvc framework in Java), i like symfony more. Because it's easier to use and faster to implement. Maybe we would give thanks to the agile nature of PHP.

But both of them have some same features more or less:

the Factories: In struts 1, it depended on the well-form nature of java. you can extend or implement classes from the framework core classes. With struts 2, it uses the famous "Spring" lib(optionally , xwork has his own also). The concept of Ioc (inverse on control) give developers a better chance to extend and replace the logic of the original framework without changing any code. actually ioc is everywhere in struts 2 from populating request parameters to actions to getting a DAO object.
If symforny could introduce Ioc, i think it will be more attractive.

Filter Chain: 5 years ago,(struts 1 for instance), we just used filter in Java. here filter is a real filter which basically pre-excute some logic before the main one. But in struts 2, it changes the name to interceptors (interceptor chain) which do the same as "Filter chain" in symfony.
But what can be improved is : symfony should have a interface-like class (maybe abstract class) who contains 2 method : preExecute() and postExecute(), then any subclass 's logic is much clear. Since i've seen some bug caused by putting post-execute-logic wrongly before $filterChain->execute(); by mistake.

Configuration Cascade: very nice feature. struts should learn more from this(to improve at least).
But now grails (something like symfony,rails in Groovy running in JVM) has this. btw rails 1.2 's performance is much better than before.

Plugin: as developer, u can make your own plugin easily for both frameworks. and the plugin repository has a lot of nice off-the-shelf plugins.
since symfony auto-load mechanism is not as robust as java's, it will loose for performance sake.

Controller adaptability: as said before, with Ioc you can easily extend it to meet your need.

View: same as Controller. in java, you can also choose which tech you would like to render the page. like freemarker, Velocity, or the traditional JSP page. very flexible, right?


why i like symfony more:
1. it has command-line utilities which speed up development and save you from the boring configurations and machine steps.
(grails has the same functionality, so i like grails as well :))

2. symfony cooperates very well with html tags and Ajax. i have bad impress of ajax support in struts and not good experience with tags. Symfony does it really good. Especially for ajax support, the built-in is for prototype, and you can easily switch to jquery using plugin.

there is a lot to say, like the model level, performance tuning, memcache......

hope we can talk more shortly.

5 comments:

  1. Hm,

    Struts is not exactly the same kind of framework than Symfony. If you would to compare a Java framework with Symfony, a framework like Play! (http://www.playframework.com) is perhaps closer ?

    ReplyDelete
  2. Struts? Seriously? Why would you compare anything to Struts unless you're trying to compare the most obsolete frameworks against each other? There are plenty of better Java MVC frameworks out there. Don't get me wrong, Struts was cool when it came out...9 years ago. If you're looking for other frameworks, here's a fairly good source: http://en.wikipedia.org/wiki/Comparison_of_web_application_frameworks

    ReplyDelete
  3. Mitch. You should know that Struts2 is not 9 years old and the problem is more that comparing different kinds of framework makes no sense. Struts2 is not a RAD style framework like Grails or Symfony. But it has definitely its advantages. Its far more modular than most other MVC frameworks, but yes, you have to do more coding with it.

    ReplyDelete
  4. I have worked with both the frameworks, the best feature i like with symfony is the crud generator and now the doctorine plugins is just simply touching the sky in comparison with hibernates in java, java have to do still more to get rid of the hazy and complex configurations part. There should be a CRUD generator designed for JAVA with struts and hibernate and plugged in struts, we can have a build a simple project control panel based on that which would make struts more easy robust and a true RAD tool without compromising the securities and facilities of java

    ReplyDelete
  5. Why am I here reading a 4 year old thread? Because I've been a PHP developer for 10 years and thought I'd diversify into Java and just discovered Play, the Java Framework, which was mentioned above. All I can say is WOW -- Symfony and Play are so similar they are probably 90% identical aside from a few minor syntax and construct differences. I'm glad Play was mentioned here or I may have never heard about it at all. If you know Symfony, you basically know Play, people! Very COOL!

    ReplyDelete