Javascript Libraries - Friend or Foe? ===================================== Simon Willison, Dan Webb, Peter Paul Koch, Stuart Langridge, Cameron Adams What's a Library? [simon w] Reusuable code, solves a common problems, patches How many libraries? [stuart l] 200 million [simon w] 2.5 new ones every week What's good about libraries? [Dan] sick of copying and pasting functions into a file. Other programmers would laugh and tell you that you can't cut and paste. Some people say they fix the problems for you. Simon has experience of Yahoo's corporate environment... [sw] for full details go to Nate's talk. 3 main problems - javascript event model, connections back to the server, things the browser doesn't support like animation and drag&drop. Drag and Drop is really trendy, nightmare to build from scratch. [cameron] One of the advantages of Yahoo libraries - you get the experience of yahoo in your code. You do test it? [sw] Have this idea of graded browser support - A Grade browsers are ones Yahoo Properties have to work flawlessly in, yahoo libs are tested in all of them. SHouldn't rely on them but it's good to know they will work in that environment. What's wrong with libraries? [Peter] People rely on them, but only if you know what they're doing. Otherwise you won't know how to solve an obscure browser bug. People tend to use them too quickly. Ask the audience - who's using javascript libraries regularly? Web Developers are independent, I want to know how it works in browsers. Libraries tend to obscure that, and do so too much. [d] with javascript it's difficult to get away from the uglyness (look at panel). Libraries suggest you can do whizzy effects without knowing javascript, but you use them for any amount of time you find yourself using the source code. [sl] how many use javascript? about half of audience are doing javascript with no libraries. Goal of reusable code, that's what's the libraries try to do. Joel Spolsky, law of leaky abstractions, if something doesn't work you're completely sunk. You're not learning what it's doing you're learning the library. [c] "abstractions should be for abstracting work" [sw] "Law of Leaky Abstractions" is a classic - javascript is leakiest set of abstractions there is. More evils? [dan] many of the major ones take the traditional approach of being monolithic, large, do many things, all or nothing, but if I only need this little bit then have to use the whole thing. People are downloading these things, I'm concerned about that, don't want user to download more than they have to. [sl] Dean Edwards was looking at Yahoo Libraries, tree widget loaded 250k of libraries. Whole point of code reuse, but then if you want to do one tiny thing you have to load the whole library. [d] Dependency management is one thing that differs between javascript and traditional programming. One of the main reasons why people aren't using libraries, would rather use atomic functions. [sw] known and understood techniques for avoiding this - caching, downside is that you go to one website and download YUI library, then go to another and you get a different. Dojo are looking at edge caching, get your code on one server - if everyone links to the same file, get that. Minification and other tricks for shrinking code size. [sl] Edge caching only works if you're yahoo, doesn't work for my library. [d] would be interesting to see a service where you can host some javascript libraries [sl] not much collaboration between libraries - if you want one thing from 2 libraries, then you end up having to include all of both [sw] disagree, mochikit has packaging system, dojo has one, jsan is an attempt to do the same, mochikit checks if dojo is running and will use it's packaging system instead. [sl] like americans and russians in 1983. Good that people are thinking about this. What makes a desirable javascript library? ------------------------------------------ [sl] I need to have written it [d] Actually like libraries that operate at a lower level, that fix bits of javascript. Average DOM scripting you always work with events, always working with lists of objects and nodes, things for easily working with lists I really like. Like easy ways to select nodes, things like cssquery, useful to me. Don't want a calendar component - have different needs? [c] boutique vs department store? [d] jquery - aspects of that I like, compact and just deals with selecting nodes and doing stuff with them. 90% of what you do when you're DOM scripting. [p] has to be small - pick code snippets you need and put them in you're own library. Forced to think for yourself. [d] Cutting and pasting functions is a bit tedious? [p] principle has to be that you choose your own components. Know what I need. [sl] that works if you're ppk. most people are not javascript genius. I want a library that does everything I want as is 5k. Don't want a noddy thing that doesn't do much. (argument if browsers and javascript is crap?) [sl] would you use a small library that made things easier if it was smaller? only half the audience would. [d] don't you think there's a baseline? basic stuff you always copy and paste? [sl] javascript libraries are very useful if you write gmail. All I do is getelementsbyid and walk the node. [p] what about classname, or event libraries? [sl] would like it to be a lot easier to do DOM scripting stuff, but I don't think we found something that does for decent programming languages did for c [sw] desirable attributes, dependent on what you're trying to do. working out if it's good enough for you to use - has to be documented, needs to be a community around it, you need to be able to understand what's going on. Is the source code clear and sane enough? If there are bugs am I going to be able to dive in and fix that. Pet peeve is libraries that don't respect javascript - "basically a toy, if you use this library we'll write you javascript for you". Java to Javascript compiler in GWT - makes web development more like swing. [sl] what .net stuff does [sw] ruby on rails rjs - write ruby that will be turned into javascript. Partly because of the leaky abstractions, but javascript isn't a bad language. Respect it and you can get a lot out of it [p] javascript libraries that treat javascript as javascript [d] big difference between taking good ideas and implementing them, and forcing it to be like your favourite language. [p] programmers don't want to learn javascript [sw] this way lies madness Are Libraries guns in the hands of children? -------------------------------------------- [d] javascript is a gun in the hand of children. late 90s I was doing DHTML hacking, realise my sins, now it's come back again, but we're seeing the same mistakes, every day there's another ajax homepage. Don't think libraries make it any worse. [p] don't make it any better either. [c] scriptaculous? [p] people are more interested intellectually, everyone had floating