Strong opinions, weakly held

Beware excessive abstractions

jQuery creator John Resig warns developers away from libraries that hide JavaScript behind other programming languages, and makes a great point about relying overly much on abstractions to make your life “easier”:

When you use a pure-JavaScript library (such as jQuery, Prototype, Dojo, Yahoo UI, etc.) you are still programming using the JavaScript language. In the case of jQuery a large number of users, who have either never programmed JavaScript before or never programmed before, acquire a good grasp of how to use JavaScript – accented by the use of the library. A pure JavaScript library makes annoying tasks simple, the largest of which being cross-browser support. It does nothing to dilute the quality of the JavaScript-authoring experience. In fact I would argue that JavaScript libraries do much to give JavaScript a particular style and feel. Code written with Prototype feels very different from code written with jQuery – and this is fine since it’s giving the user the option to develop in the JavaScript language how they best see fit.

In the case of these language abstractions you are gaining none of the benefit of learning the JavaScript language. When a leak in the abstraction occurs (and it will occur – just as it’s bound to occur in any abstraction) what resources do you have, as a developer, to correct the problem? If you’ve learned nothing about JavaScript then you stand no chance in trying to repair, or work around, the issue.

This is a problem I often run into with developers who rely on persistence/ORM frameworks. They’re great, but if you’re dealing with relational databases, you really need to know SQL. These frameworks make a nice supplement, but they’re no substitute.

Update: Be sure to read the comments for a well thought out counterpoint.

1 Comment

  1. I’ve been using GWT for a while now and I disagree pretty strongly with what he’s saying, actually. 95% at least of my GWT code is logic that is much more easily and safely written in Java than in Javascript. GWT provides excellent access to most of what you need to make a good user interface. I’m a reasonably proficient Javascript programmer but it’s just not a very good language to program in. Yes, I have the Good Bits book, but read the chapters on the Bad Bits and you’ll see all the things that are unfixably wrong with the language.

    A separate concern is that I am simultaneously writing server-side code in Java and client-side code. Javascript has a radically different kind of object model to Java which requires a great mental shift. It also has little overlap in datatypes, especially when it comes to numbers, maps, arrays, and so on. Being able to program the client-side code in Java means I don’t need to make large context shifts all the time. Very little code is actually shared between the two sides, but the programming model is similar.

    I think this is pretty different to the ORM problem. There the problem is that you’re translating one model (the relational database model) to another (the in-memory object graph model). These two things don’t map directly at all. In the Javascript/GWT case, you’re mapping between two complete programming languages, and though the details are different, the model is very similar. You don’t lose much by doing it, any more than you lose very much by compiling C to machine code.

Leave a Reply

Your email address will not be published.


© 2016 rc3.org

Theme by Anders NorenUp ↑