Saturday, January 19, 2013

JavaScript is not the problem

I've been reading about different new languages in the works that compile to JavaScript. Some examples: Microsoft's TypeScript, Google's Dart, CoffeeScript, etc. They all 'fix' issues in JavaScript that we all know and dislike. Stuff like the 'this' behavior, no block scope, and a lack of even optional static typing. 

I agree that there are plenty of things in JavaScript the language that are annoying and should be fixed. Now apparently everyone thinks that if we just fix JavaScript the web will be a better place.

I've spent the last seven months or so working on a web application. This particular application looks like it should be on the desktop. It is single-page, has a very traditional desktop layout, and can be safely identified as 'rich'.

Out of all the pain that has arisen while developing, the least of my pain comes from JavaScript. In fact, I enjoy using JavaScript and paid the price of learning its quirks and problems. There was an initial learning curve yes, but I'm comfortable with it and can avoid its flaws.

My real problem is not with JavaScript, and I don't think the solution to turning the browser into a 'real' application platform is fixing JavaScript. 99% of my painful, time-consuming tasks are from the DOM (and to an extent, browser inconsistencies).

The DOM is just awful. It's not meant for applications that you would normally write natively (if it wasn't for that good ol' write once, run anywhere). I've been working with the Dojo Toolkit, and it's been a fairly positive experience. This particular framework solves a lot of issues cited with JavaScript, such as the lack of modules and traditional class-based inheritance.

However, my time is spent figuring out how to get my tab containers to fit their content, or resize in a modal dialog, or render charts correctly, or making sure text fields look ok when they're localized, whatever.  Some of these are component issues, but the underlying issue is that the DOM is terrible for real applications. It's not built for components, it's built for documents like the name suggests.

The browser environment in general sucks. Why can't I show the print preview dialog instead of jumping straight to the print dialog? Memory leaks due to the abstraction of the DOM. CSS file limits in IE. Trying to copy something to the clipboard. No, the browser was not designed for this. I understand that, but there are no good alternatives. Flash has its own problems, no other plugins have taken off (Silverlight? Java applets? Ha!). Going native is looking more attractive.

It's not a fun experience, and none of these issues are solved by sticking another language on top of JavaScript.