A lot of things on the internet broke this week when npm (node package manager) unpublished the left-pad
module (more detail on The Register and the official post on the npm blog. Two things have stuck with me from the story: you can’t rely on JavaScript; look carefully at your dependencies.
You can’t rely on JavaScript
Things break, and JavaScript breaks particularly easily. I love JavaScript, but I don’t trust it. In this case, though, it wasn’t JavaScript’s fault. npm unpublished a module, so it was like a connection was broken, like a CDN went down. This broke a bunch of JavaScript frameworks and tools (Babel, Ember, React native). If your app depends on one of these, then you’ve probably had a bad few days. If your app is built with Progressive Enhancement, then you’ve probably had a much better few days: it’s been business as usual (almost!).
I’ll be talking about these kind of things (and lots more) at the Meteor Cape Town meetup on Wednesday 20th April. Come and watch me say “don’t use Javascript (sort of)!” to a bunch of people who use a JS framework. :)
Look carefully at your dependencies
Since reading Patrick’s post about Libraries last year I’ve become (ever more) obsessed (than usual) with minimalism in code, trimming things down to just what I need, killing my dependencies and simplifying things as much as I can.
The left-pad modules feels like a good example of swinging a bit too far in the hyper-modularisation, lots of tiny single-purpose things, direction. It’s 11 lines of code that pad a string on the left. That seems like the kind of thing that should be part of the utilities blob of an application, not an external dependency. David Haney has a good write-up of this, asking “Have We Forgotten How To Program?”.
I try to make robust things that are simple to work on
I try to build things with Progressive Enhancement: I don’t rely on JavaScript for any core functionality, and I add layers of shiny for browsers that support the fancy things I want to do. I try to minimise my external dependencies so that I understand more of the code that I put out into the world.