Saturday, February 23, 2008

Mixed Languages and Debugging

JavaScript and server-side languages can work well together ... if you don't set them on the same task.

The programmer's mind is like a kid with a dinner plate - they don't like foods to touch each other. (Ugggh. Terrible metaphor, but what the hey.) Kids have problems debugging food. If they get gravy mixed into the applesauce and it doesn't taste good, there's no way to get them unmixed. Adults probably don't mind it because (1) they know through experience which foods mix well (2) they have given up trying to keep food apart (the "quiet desperation" theory).

I'm not opposed to using more than one language. In fact, that often makes the problem much more decomposable and succinct. What makes me leery of technologies like Google Web Toolkit and Java Server Faces. They try to cover up the language blending, as if a parent can solve the touching-food problem by dousing the whole plate in melted cheese or something. GWT tries to cover up the underlying JavaScript by generating it out of Java. And that's great until you have a problem on the browser side. Is it your code? Is it the translation process? Is it the supporting code provided by GWT? Who knows? You are left with a "this.myProperty is not defined" error, and it's up to you to fix it.

The Dojo Way (tm) is to cleanly separate the tasks of a web application. Styling in CSS. Layout in HTML. Client side logic in JavaScript. Data-providing web services on the server. Now that is like a compartmentalized dinner plate. A little bit of a lot of variety, and nothing touching. You can generally debug these elements as black boxes. Someone works on the web services, writes the unit tests against them without the client. Design gurus do the CSS. The application logic is in JavaScript, and in Dojo you can package them in nice little bite-sized widgets. The app talks back to the server to execute bits of business logic. Very clean. Very nice.

Debugging JavaScript is not a perfect science, unfortunately. And I'll talk about that in my next post.

No comments: