How JavaScript libraries save and waste your time

June 6th, 2009 Comments Off on How JavaScript libraries save and waste your time

JavaScript libraries are the best thing to happen to JavaScript since it was shoehorned into Netscape, way back in 1995. They are also a nightmare for developers. How can this be? Certainly, with the breadth of libraries offered today surely there must be one, best choice. Like many things in life, it’s never as easy as picking the best or even the least horrible.

History

Let’s rewind a bit. JavaScript was invented by Brendan Eich, originally under the title of Mocha. This next bit always gets JavaScript aficionados’ (like myself) skirts ruffled but JavaScript is not a true programming language. It is a scripting language, weakly typed, dynamically interpreted and without a true OO structure. There’s no garbage collection, no typing and very few data structures. By comparison, C is downright drowning in features.

As if being a scripting language wasn’t enough, JavaScript is also implemented in different manners and levels by the many browsers, suffers from proprietary functions (XMLHttpRequest, anybody?) and can fall flat on its face if the DOM isn’t properly rendered. It’s a veritable mine field of hacks and work-arounds to get a decently-sized system working for the majority of the web.

Of course every language has its disadvantages and in face of AJAX, new JavaScript engines and the growing amount of mashups and services offered on the web, JavaScript continues to shine in its flexibility. The language hasn’t even released v2.0 and businesses like Flickr, Google, Yahoo leverage entire products on JavaScript. There must be something to the language, so what am I getting on about?

Lifespan

Like it or not most JavaScript libraries are immature. Sure, there have been great guys like Dean Edwards, who have been cobbling together scripts and hacks into a convenient wrapper, calling them a library. I’m not knocking that work at all. It’s paved a long road to where the community is today and the work is not only well done, but still relevant.

What I am saying is that full libraries with helper functions, effects, AJAX and the other myriad of tools which can be provide have only been on the scene for a short time. They have experienced a massive burst of growth, thanks to active communities and their use on high profile websites. They have explored new and innovated means of developing UI and data interaction and have even begun standardized competition between each other.

Still, who knows where these libraries will be in two years, five years or ten years. I can hear the collective scoffs of developers right now. Just upgrade the library, you say. Keep with the times, grandpa! It’s not that easy, buckaroos. When you’re developing for an enterprise you need to think about things like a life cycle measured in years,  vendor support and development. I don’t want to be responsible for digging through a few thousand lines of JS code in a few years just because the new IE now requires me to hack up my library so that Windows folk can validate my form on the client side.

Truth be told, the only library with plausible hope of long-term life is the Yahoo! User Interface library. It’s well designed, relatively fast, has had some great minds working on it and Yahoo! isn’t likely to disappear any time soon. Great though the rest may be, there is no proof that they’ll be around next week, only the hope.

Syntax

This one is so obvious that many people overlook it. Learning a new JavaScript library requires learning new syntax. This isn’t a bad thing because the point of many of these libraries is to do more work with less code. Being able to select elements based on CSS selectors by typing $$('.myclass'); is a veritable dream come true. Still, each library has its own flavor and none of them are fully compatible.

For 90% of the users, the syntax is a time-saver and becomes second nature. Those last 10% are folks who just want to get something done in JS and can’t be bothered to deal with new syntax or, heaven forbid, are transitioning from one library to the other. Using some clever code an automated conversion script could be generated to make the move from one library to another but this is more work in yet another language.

It’s just one of those Catch 22 situations where you’re damned if you do and damned if you don’t.  Thankfully, I fall into the 90% of folks who love their new syntax and wouldn’t trade it for all the money in a hobo’s pocket.

Performance

This is a tough topic to cover. Until slickspeed there was no universal, honest test of libraries. It was mostly developers talking about how they made their iterators 500% faster or have new CSS3 selectors. I’m sure more testing suites will be developed but for now it comes down to developers deciding which features are best supported in a library and hoping that either the speed is quick enough or that it will improve in the near future.

Capabilities

Support

I eluded to this earlier but it deserves more attention. Support from your third-party is crucial to anybody who is serious about coding. Trust me, I love hacking code into the wee hours of the night, but only when it’s my code. I do not consider it a good time to be debugging someone’s plugin or extension because they didn’t properly test and I’ve stumbled upon an edge case.

A good vendor will have dedicated support staff, an active community – perhaps with a sponsored forum – and, if you’re lucky, a few developers dedicated to the product. There will be the opportunity to pick up the phone and get support 24/7, maybe even have a local technician come out and do on site support. Sure, these services aren’t free, but in a crisis it’s reassuring to know they’re available.

Honestly, I don’t expect that kind of support from any JavaScript library. Yet. Google is huge and can support their own code as much as they please. Joe website guy has enough time on his hands to support what he writes and isn’t under enterprise-level support needs. It’s that middle ground where you have a dozen projects running simultaneously and the project manager doesn’t understand why you allocated 10 hours to the menu system but suddenly you’re telling her it will be 20 because you’re running into an obscure bug in IE 5.5 for the Mac.

With the the JavaScript performance race between Firefox and Safari (IE8, you still don’t make the cut) JavaScript is prime to become a crucial aspect of companies with internet-based products. I know that sounds like something out of 1995 but, really, there are many popular applications which either do not use JavaScript or have it as an ancillary feature-add.  As the canvas tag gains more support and JavaScript becomes faster entire apps could move their features online. None of the half-functional things like Word online but real applications: Page layout, bitmap editing, 3d modeling, you name it.

None of that is going to happen without support from vendors. Do you really think Autodesk, makers of heavy applications, really wants to invest the time and long-term money into writing a 3ds Max JavaScript library? Not likely. They’ll want to take money which is pennies to them, say $15,000, and license a library that does what they need. They’ll do this because when things break they can just pick up the phone and have it fixed. It’s cheaper to pay $250 in a day’s worth of support than keeping a $75,000 salaried employee around all the time.

Comments are closed.