|
... and why I chose it over GRAILS, Ruby on Rails and Code Igniter...
I have spent the last few weeks completely immersing myself in Symfony, the PHP development framework for web application development. To be honest, I believe GWT with GXT represents a much more visually appealing interface but there are good reasons to use a regular framework instead of Google Web Toolkit. For one, all the frameworks I mentioned above offer three important functions, all more or less absent in GWT:
- ORM, object relationship mapping. It is the ability to free the developer from the minutiae of having to focus on exactly how to serialize objects (often with complex relationships to each other) to databases (in general relationship representations of tables). Modern development should simply no longer require you to focus on how eactly transform objects to SQL, often having to take different databases with slightly different syntax into consideration. Flushing an object has to take many things into consideration such as objects emebbed in objects, pointing to other objects, field representations and a host of other issues. SQL deals with nasty things such as foreign keys, stored queries, incompatible field formats between SQL dialects and much more and ORM comes to the rescue. Yes, GWT (such as any Java solution) offers JPA, often in the form of Hibernate (there is a library that bridges GWT and Hibernate, Hibernate for GWT with the name itself being a moving target) but I decided to let this mature a bit, also because of the other reasons mentioned below.
- MVC or Model / View / Controller speparation. This is essentially the programming pattern of serparating data from presentation and business logic from data. Why this is a good idea is beyond the scope of what I wanted to pen but there is tons of literature about it out there and I encourage you to have a look at it.
- Routing or the ability to form URLs which are independent from the underlying layers that process them. This offers the advantage to make your URLs more readable, offers permalinks, better spidering and in general URLs that make sense. http://www.example.org/reports/02/01/2009/travels makes a lot more sense than http://www.example.org/index.php?reports=y&range=0201290002802009&type=travels.
In addition each of the frameworks offers a host of additional features which make development easier and facilitate an agile process. Again, one of those words that requires a lot more explanation and Wikipedia certainly has a lot more to say about it than I could here.
Differences are also manifold and fall into a variety of categories:
- Language: Symfony and CodeIgniter are PHP frameworks. While I am not a PHP expert by any stretch of the imagination it is similar enough to Java and C++ and a number other object oriented languages that I have done a great deal of work in to make me feel pretty much at home. Unlike Java or C++ it is an untyped language and programs developed in PHP often referred to as 'scripts' which really doesn't do it justice, just like Python is a lot more than a 'script'. Bash is a script or a Windows CMD file is a script, failry limited code. PHP 5.x is a full blown and fairly well-designed OOP language that is nothing short of Java in terms of what you can do with it. There is tremendous community support for it, endless libraries rfor the taking and performance on a properly tweaked server rocks. There are freely available (non-commercial) debuggers which work well (such as xDebug), something that cannot be said for either Groovy or Ruby. Both of the latter offer debugging tools but none of them come close to xDebug.
Groovy (GRAILS) is also an untyped language which sits on top of Java. It is a precompiler that returns Groovy code into Java byte code which is then executed in a JVM. As such it requires a web server that supports Java class loading such as Tomcat or Jetty, to mention some free ones which are in wide use. Having said that I should add that Symfony also likes a lot more control over its environment than what your average GoDaddy style shared hoster has to offer (CodeIgniter is quite happy to run for $6.95 on a Go-Daddy oversold server). In any case, looking at a server solution will run you a little more money but also offers a ton of flexibility. I opted for Echoservers where a VPS to my liking runs me about 25 bucks/month (yes, the web site offers cheaper solutions but have a close look at the details). They offer a variety of Linux based VPSs using a cheap virtual option (HyperVM versus something like Virtuozzo) but it keeps the cost down. I have to say in their favor that I have had zero stability problems, something that is often criticized in respect to HyperVM. After looking at the various Control panels and configurations I tossed all the predefined installs and built a CentOS server based on the Virtualmin/Webmin solution from scratch. If you are looking at doing the same thing, make sure you feel comfortable with the Linux command line and the various packagers (Yum in my case). I eventually wound up with a machine that does exactly what I want it to, offers all the PHP features I wanted (XML/XSLT processing with the APC accelerator) and runs Tomcat on top. So I could have chosen Groovy. But what Groovy's developers are touting as advantages overr Java I personally consder huge drawbacks: Groovy is much terser than Java. I am sure the Groovy heads used to love Perl. Exceedingly complex code in just a few lines. They suggest that this makes the code less error-prone whereas I would contend any mistake will have huge ramifications. Humans benefit from redundancy and Java is redundant. It's good to have things stated in two words isntead of one. Certainly, some of Java's syntax is cumbersome but it seems to work for an awful lot of people. I just don't like Groovy. It's tempting to try to throw in some Java code and one quickly realizes that that doesn't work. It's kind of like Java but it doesn't digest Java code so it adds a layer of confusion. I think it's a bad idea. I'd rather run Jython than Groovy. As a matter of fact, I see no need for Groovy and is an answer to a problem which has already been addressed a dozen times. It's an answer to a rpoblem that no longer eists. Groovy claims almost zero learning curve for Java programmers but I consider the learning curve exceedingly steep. I read two individual books on the language, one of them written by the author's of Groovy. They were confusing, provided eamples instead of structured syntax and an overall gee-whiz approach.
Rails is written in Ruby. Ruby is very different than Java, Groovy or PHP. It's well designed and according to some people allows code that is about half as short than PHP to do the same thing while still remaininng readable. It's a new language designed from the ground up so there is a lot less confusion in respect to syntax as opposed to Groovy. It is also untyped but appears to perform a lot better than PHP. I am not sure how much that should impact decision making: Grails web site makes some pretty outrageous claims itself but in the end it matters to me less than many other factors. In the end it depends how much control you have over tweaking the box that the code runs on and a well-greased PHP server is likely going to run better than a run-of-the mill Tomcat. Theoretic numbers mean less what I can practically achieve without too much effort. Symfony's caching, APC acceleration and an optimizer can do a lot for the PHP itnerpreter, in effect turning it into a byte-code machine.
- Admin generation: 75%+ of the applications that I have worked on uses a backend administration of data models. The frontend code is minor. These are business applications which require the manipulation of large amouns of data, easy ways to query, sort and massage it in other ways. Data entry (which may be input from web site visitors or clients of sorts) occurs in the frontend and is sensitive to cosmetics but a solid backend which is flexible and can easily accommodate a variety of requests and can quickly be cranked out is my #1 concern. I have generated these backends time and again only to have to regenerate large portions because data was added to database tables or new data relationships been established. This is a major headache and consumes most of my time. Whether this backend is styled in a particular way has little significance. Functionality is everything.
In this regard Symfony really delivers. Administrative backend generation (and I am not referring to simple CRUD sekeletons but extensive data manipulation driven by a set of definitions which can be adjusted at the drop of a hat) is a no-brainer. It takes minutes to generate administraive functionality with sort, filtering, one to many and amnay-to-many relationships. Neither Groovy nor CodeIgniter offer anything comparable. Rails does not offer it out of the box but there are a few addons that offer something along the lines of Symfony's generator. However, I found the links to be dead or the websites that offered the code looping in redirection which did not exactly infuse me with confidence.
Mind you, do not get administration generation with Scaffolding. All frameworks offer Scaffolding, i.e. a quick and dirty way to generate and environment to Cread, Read, Update and Delete data. Scaffolded code is generally further massaged whereas much of administration works out of the box and requires much less customization.
As far as I can tell Symfony shines here and has little real competition. I'll gladly be convinced otherwise.
More in part 2 ...
|