The fog of libraries

It’s pretty foggy at the moment, here in the Midlands in the UK. It’s been like it for two days. Stepping out of work the other day, after dark, with each street light at the centre of a glowing aura, made the street I work on — in the centre of Birmingham — look like something Victorian. Like a woodcut from a Sherlock Holmes book. I wouldn’t have been at all surprised to see a hansom cab pull up and a man with a sword-stick get out.

Of course, I wouldn’t have been surprised to see Jack the Ripper hiding in a doorway either.

It made it feel like it was nearly Christmas, which it is. It was really rather difficult to remember that it’s still the same old modern street underneath.

So now I’m going to talk about JavaScript libraries. You’ll see how the fog is relevant in a bit.

There’s been quite a bit of discussion of libraries recently. Jeremy Keith writes:

There’s a lot of talk about JavaScript libraries, including a lot of hype and cheerleading, but I think that maybe the discussion is disproportionate to the amount of people actually using libraries. Personally, I’m somewhat mistrustful of using other people’s code (I’m a bit of a control freak) and I thought I was in the minority, but having spoken to people like Stuart and PPK who share my feelings, now I’m not so sure.

PPK himself says:

a quick and non-scientific poll @media showed that only a minority of JavaScript developers use a library; the others just code by hand. But JavaScript libraries are cool nowadays and will remain so until the Ajax hype blows over.

Chris Heilmann complains mightily about libraries in general, although about specific details rather than about the concept of using libraries as a whole.

And Roger lays into people who use them, too:

Overuse of JavaScript frameworks/libraries. Back to the 90’s, baby, except they were called DHTML libraries that time around. What is it with people learning a JavaScript library instead of learning to write JavaScript? It’s like learning Frontpage instead of HTML. Yes, script libraries can be great. But not when people use them because they can instead of because they should.

Lots of people are getting into the whole idea of using a JS library. Among the cognoscenti, though, there’s starting to be a bit of a backlash. “Putting guns in the hands of children” is how the discussion was phrased during our JS panel at @media 2006. The idea behind this discussion is that libraries give developers access to lots of cool powerful stuff — hiding and showing areas of the page, Ajax requests, animation — without them having to really demonstrate that they know what they’re doing. It’s an argument with a certain amount of truth in it; it’s used a lot by gun-control advocates as well, because if you have to go through five years of training to become a karate black belt then you’re much less likely to kill someone after leaving the pub, and much less likely to accidentally kill a member of your family, than someone who’s bought a Saturday night special and hasn’t had any training.

On the other hand, it’s a pretty elitist viewpoint. Apparently, you shouldn’t be allowed to use JavaScript unless you’re an expert. New developers, people just looking to get their job done, someone who wants to apply a cool effect: these people are not wanted in our glorious new revolution. Dammit, programming ought to be hard: it keeps out the idiots. This attitude comes up a lot, a lot, in the Linux world, and it’s one of the reasons why Linux is perceived as being harder to use than, say, a Mac: I’m surprised that there are Mac people out there who are highly happy* with the ease of use of their computers and don’t have to understand one iota about how they work under the covers, but still believe that JavaScript developers should be held to a higher standard.

What drives adoption of technology is real ordinary people, people who come in at 9am and clock off at 5pm and don’t think about work outside those hours, being able to use those technologies. JavaScript libraries bridge that gap. I’ve changed my opinions on this quite a bit; I used to hand-code all my JavaScript myself, and now, for quite a few of my projects, I use jQuery. I just got sick and tired of thinking: how do I hook up events in IE5.5? Is it different to 6.0? Where’s that cut-and-pasted code for creating and using an XMLHttpRequest object in every browser? I’d ended up building a tiny library for myself of bits of code I cut-and-pasted into every project, and my library was inferior to others because I don’t do as much testing in every browser. So, why not use a library? I couldn’t think of a reason. Now cross-browser testing is John Resig’s problem, which is handy.

The fog hid the nastiness of Birmingham. Libraries hide the nastiness of cross-browser scripting. While it’s easy to say that you should have to know about the nastiness, this is the season of goodwill. It’s nice to step out of your office into a foggy lit street that looks like a scene from It’s A Wonderful Life. Let’s not take that away from people.

This doesn’t answer Chris Heilmann’s objections, though, and that’s because they’re a damned good set of objections. The libraries we have are in general not well documented; a list of functions that the API provides does not help if you know what you want to do but not how to do it, because you have to guess at what the library might have named this function. Making the documentation available only online doesn’t help either, although this is something that really could be fixed by someone other than the main library developers — most documentation issues, including a proper decent set of examples of how your library can progressively enhance a page, with a case study or two, can be fixed by people outside the core team. So if you really hate this issue, jump in and get involved by building some docs for the library you like the most.

None of these problems are insoluble, though. Part of the issue is that JavaScript developers divide into:

  1. People who aren’t hugely experienced with JS; these are at least some of the target market for a lot of libraries
  2. People who are experienced and are writing a library
  3. People who are experienced and think that you shouldn’t use libraries unless you have the experience to not use them
  4. People who are experienced and willing to help

Of those, category 1 people aren’t going to help write documentation very much, or case studies, or browser support matrices, because they’re consumers of that information rather than creators. (Those of you who think “yes! we’ll have a huge army of people contributing!”, take a tip from the Linux world, where we’ve been using that model for code since the beginning; it happens, but not all that often.) Category 2 people are too busy writing a library to build supporting stuff around it. Too many of the remaining: people who could be helping to make the libraries we have better, and better documented, and more appropriate, and less stuffed to the gills with flashy but bad effects, are too busy repudiating the entire concept of libraries. They’re in category 3. If we can collectively, as a community, move from category 3 to category 4, and make the libraries we have great, then there won’t need to be any kind of objection to them. Let’s try and help.

9 Responses to “The fog of libraries”

  1. Excellent post, Stuart. Finally, someone with a sensible perspective on JavaScript libraries! I suppose I’m floating somewhere between numbers 1 and 4 in your classification scheme, at least in terms of the experience. But I’ve been so taken with jQuery — its elegance, its efficiency, its fun — that I can’t help but share my knowledge when I discover something new. That’s why I started the Learning jQuery blog a few months ago.

    I guess I should head over to Chris Heilmann’s blog now and see what his objections are. Thanks again for the good read.

    Karl Swedberg
  2. Stuart - These are some excellent points. It is a very challenging topic, in general - and one that I’ve been looking at in depth. I think many people trivialize the work that’s done by a JavaScript library - and in many ways, trivialize the development process that surrounds them.

    I feel that a JavaScript library is more like stdlib in C++, Python’s standard library, Java’s Standard Library - Yes, you could write all those things from scratch, in fact, many purists think that you should! The problem is that the skills required to write a really good JavaScript library (and, therefore, really good JavaScript code) are way beyond the skill level of the majority of JavaScript coders. (Especially ones that have good teams like Dojo, Prototype, Yahoo UI, and jQuery)

    Its really easy to trivialize a JavaScript library for “flashy effects” - but really hard to do so for solving hard problems like cross-browser computedStyle, HTML insertion, and DOM Traversal.

    Christian’s criticisms are some of the best that I’ve read so far and stick very well. For that reason, we’ve already started work on a new batch of jQuery tutorials, and shining more light on the jQuery development process.

    I think that in a year, JavaScript developers will be talking about JavaScript libraries very differently, but in a very good way. But in the meantime, libraries are helping a lot of people “get the job done” faster, and more simply, than ever before.

    John Resig
  3. John: absolutely. I use jQuery precisely because I can just use $(document).ready() and it Just Works, and I don’t have to think: how do I do this across browsers? The problem is that once library writers have built a solid and consistent simple API to the stuff that people need — running onload, hiding and showing elements, fetching a URL with Ajax — then it’s difficult to say “and that’s what my library does”, and stop work on it. You have to add new stuff so it looks like there’s still lots of work going on with it, and that’s where all the flashy effects come in, because what else is there to add? The Dojo team are adding things that aren’t flashy effects, like dojo.storage, and that’s great, but that’s intensive high-level research stuff; not many people are prepared to use things like that just yet.

    sil
  4. The approach that we’ve been taking with jQuery is to actually reduce the number of features in the core library - keeping it lean and tight. The majority of jQuery development, right now, is in improving its speed. As it stands, we’ve achieved 4x-10x improvements in selector speed, beating virtually every other selector library on the scene. (This improvement is coming out in the upcoming 1.1 release.)

    Because jQuery has its plugin architecture, we (the dev team) don’t feel compelled to create extra features - that can be left to any common developer. Instead, we just get to focus on creating ultra-robust code that we can be proud of.

    John Resig
  5. John: yes. That’s why I use jQuery :)

    I’m trying to not call stuff out by name here, because if I wrote that I’m not convinced that libraries are a good idea *except for jQuery* then, well, it’d look rather partisan :)

    Plus, YUI’s pretty cool; dojo’s ubercool, etc. I want us, as a community, to get past the fear of library use, so we need to investigate how to do that.

    sil
  6. Well said Staurt! I think it’s time to stop bashing the very concept of libraries now. Cross-browser JavaScript is too damned difficult to write without library support these days.

    Dean Edwards
  7. Abstraction is the key. Let the community solve the problem of cross-browser issues. With these libraries, we can focus on creative thinking, and not on browser issues.

    Copongcopong
  8. Copongcopong: not sure about just abstracting away all the complexity…

    sil
  9. [...] PPK starts off by referencing a post I read last week or so from Stuart Langridge (author of DHTML Utopia, and the tech reviewer for my book), where Stuart seems to moderate a lot of the serious anti-library leanings he used to have. Ultimately however, I don’t really buy PPK’s final point — he believes that the current lack of doco means that the only people who can use the toolkits are the experts who don’t need them. He writes: [...]

    Fleegix.org : Ongoing JavaScript library discussion

Leave a Reply

OpenID is a decentralised authentication system. If you use LiveJournal or Vox you already have an OpenID; just use the URL of your homepage there. See also how to get yourself an OpenID.