Dojo and Zend: Where’s the loose coupling gone?

by jon on August 13, 2008

On the eve of the release of the Zend Framework's 1.6RC, found it interesting to read Lukas' comment on Matthew Weier O'Phinney's blog about how there were outstanding issues in existing core components of the Zend Framework that hadn't been resolved, and yet the Zend_* component library was still growing and accepting new proposals.

The last comment by Martin noted that Zend_Db still had some unresolved issues for over a year.

Matthew's response was that this was a community project and that priorities are dictated as such. Personally, this doesn't affect me because I'm hedging my bets on Doctrine as an ORM layer for PHP development.

I like Matthew's response because the Zend Framework's philosophy encourages the development of loosely coupled components wrapped up in a development philosophy that encourages open contributions, financial backing (thanks to Zend, IBM, Sun and others), Unit Testing and project transparency. Here's where things go a little wonky.

Partnership with the Dojo community

While I really enjoy the implementation of Zend_Form on the server side. It allows multiple configurations, supports validation and while the decorators are a bit obtuse, on a whole, the Zend_Form libraries thin out controllers and encapsulate the concern of data entry in a clean manner.

In this point release, however it seems like there's been a whole outgrowth of Zend_Dojo_* classes that cater to doing AJAX development with the Dojo stack. I'm not sold on Dojo as a client-side framework. Past experience with it has left me trying to sort out a large, over-specialized collection of patterns that almost do what I want but not quite. I also don't like the coupling that occurs between the data set, the client-side validation and the magic rendering of panels (like Accordian's and content panes).

An alternative architectural approach

I would rather write the events, the theme, the data and the validation separately and reduce duplication in each of those patterns rather than in the UI pattern as a whole. In short, I think they've abstracted the wrong part. The same example can be seen in ASP.NET form validators from two years ago.

With Prototype, I can rapidly mock out a site with the functional requirements and use Script.aculo.us to accent the presentation with animation. My functional specification isn't muddied with fancy visuals and it lets me focus on the event handling, validation and end states rather than the fancy effects.

By using Zend_Dojo, you won't be tempted to build a well-exposed Service Layer from Zend_Controller. The advantage here is that you lead development towards service-orientation. If you need to write a Flex front-end, or a whole new business-tier, you at least have the beginnings of a web service, whereas if your working with Zend_Dojo's declarative templating syntax, you're already coupling the events, validation and data into heavily abstracted UI patterns.

This approach doesn't lead development towards the production of a refined Service Layer, but to a specialized Dojo-friendly interface with markup-generation from Zend_Form classes into Dojo markup. I would rather see a Zend_Form Service API where developers can send / receive JSON messages to inherited Zend_Form and then have the Dojo community write an Adapter that would send / receive messages from Dojo widgets.

A year or two from now, I wouldn't be surprised if people will look at the same Zend bug tracker, asking where support for Dojo went after the Zend team jumps to the next cool Javascript framework on the block and we find ourselves with Zend_Form_SproutCore or some other dependency.

{ 2 comments… read them below or add one }

Wil Sinclair August 18, 2008 at 5:32 pm

I’ll leave the more technical response to Matthew; I’m still learning Dojo myself. As far as jumping ‘to the next cool Javascript framework on the block’, that’s not in the plans. In fact, we chose Dojo so that we could provide deep AJAX support for a JS toolkit while letting the community cover other toolkits. In short, the possibility of Zend supporting another JS toolkit is extremely low. You might as well worry about the ZF project getting ported to Cobol. ;)

,Wil

jon August 18, 2008 at 11:58 pm

I think the integration that we’re seeing between Dojo and Zend is A Good Thing and what Matthew’s design of Zend_Form leaves me certain that the integration will be well done.

My concerns are twofold:
– Zend_Form_Dojo might be the wrong kind of coupling

I would assume that Dojo integration would be at the controller level since the Dojo integration seems to circumvent the Zend_Controller architecture (I assume this because none of the code samples make reference to Zend_Controller).

As a developer building RIA’s I’m ever mindful of the Microsoft ASP.NET syndrome of spending more time learning an API for an object than working out the right design to fit the bill. Some of the ‘controls’ in the AJAX.NET toolkit could be written in minutes, however implementing the compiled components can be a huge headache.

While I can admit that I have some prejudice toward the framework, Dojo’s design seems to be serious technology investment which I haven’t found a need for yet.

- Zend Development energy on other projects that aren’t mature yet

I think that a full client-side development framework like Dojo still needs some maturing. For all I know, in two years time we’ll all be writing front-end applications in Adobe AIR / Microsoft Silverlight / Java Web Applets (again) / WebKit AJAX and the idea of writing Javascript forms and controls against a something like Dojo front-end framework will be marginalized and relegated to maintenance work.

I can rest assured that PHP as a web technology won’t be going anywhere, and with Microsoft’s support of PHP in IIS and their new IDE, it’s a safe bet, however I don’t think the client-side framework wars have been won yet.

What I can say for certain is that in two years, we’ll be sending messages via JSON, SOAP/REST and XML-based web service calls. Spending development time on maturing a JSON / XML independent would be worthwhile, regardless of where industry players would like to take the web.

I think Zend_Form_Dojo is a great project and I might be eating my words in a couple years, however I don’t think it should be part of the Zend core library. It’s adding to the time investment that Zend is already made. As a humble suggestion, I think Zend should focus on the messaging and write a Dojo adapter that serializes / unserializes Zend_Form objects and call it a day.

I think it’s also easy to be an arm-chair developer, which is why I appreciate you and Matthew taking the time to foster good blood in the community around what ZF is doing.

Regardless of my opinions, I know the value of having a strong community behind something, and while I can justify using Doctrine over Zend_Db, I can’t deny that the ZF fits 90% of development needs on projects and as such, I’ll end up (reluctantly) learning Dojo ;) . I don’t foresee myself using it over Prototype or JQuery due to its weight, but ignoring Dojo is no longer an option for any Zend developer.

Leave a Comment

Previous post:

Next post: