SlideShare a Scribd company logo
YOUR LIBRARY SUCKS.
   jsconf.eu :: 25 Sept 2010 :: Peter Higgins
BUT YOU SHOULD USE IT.
    jsconf.eu :: 25 Sept 2010 :: Peter Higgins
Me.
Dojo Toolkit Project Lead

JavaScript Engineer @joost / Adconion

Blogs Infrequently :: http://higginsforpresident.net

Codes @GitHub :: http://github.com/phiggins42

Twitter: @phiggins

Beer Drinking Expert
It’s Just JavaScript   TM




Lovable, Simple

Self Healing

Promiscuous

Ubiquitous
The Good Parts


Context :: apply/call/hitch/partial

AOP, FTW. (duck punch...)

Prototypes, also FTW

Module Loading (/me jokes)
The Bad Parts


Date() :: designed with evil.

The DOM :: also designed with evil.

with() and eval() :: allegedly evil.
Teh Libraries

Dojo
YUI
Mootools / Prototype
FuseJS (?)
EmbedJS (?)
jQuery
Your own
LOVABLE, SIMPLE.
Libraries are a crutch

Learn JavaScript first

Know enough to dislike parts

  Supplement those parts

Don’t be afraid of the word `prototype`

  If you don’t know $.fn === $.prototype, quit (or learn)
PROMISCUOUS
  Also known as Loose Typing
SELF-HEALING
BASIC AOP <3
// I can fix anything:
var oldfunction = some.oldFunction;
some.oldFunction = function(){
    oldfunction.apply(some, arguments); // closures, ftw.
}
Philosophically

   Fixes on the Natives vs Namespaced fixes

      SomeString.trim() vs mylibrary.trim(SomeString)

mylibrary = {};
mylibrary.trim = String.prototype.trim ? function(str){
  return str.trim();
} : function(str){ /* do the “fun” stuff */ };
Bind/Curry/Whatever
        Context manipulation, FTW
mylibrary.bind = Function.prototype.bind ? function(fn, context){
    return fn.bind(context);
} : function(fn, context){
    return function(){
         return fn.apply(context, arguments);
    }
}
EASY TO ABUSE :(
DON’T DO THIS:
$(“div button#bar”).click(function(){
  $(‘#bam’).addClass(“bar”);
  $(‘#bam’).css(“width”, “200px”)
  $(‘#bam’).animate({ width: “+=100” })
}).click();
To be fair ...
// easy to write bad code in any library:
var $ = dojo.query;
$(“div button#bar”).onclick(function(){
  $(‘#bam’).addClass(“bar”);
  $(‘#bam’).css(“width”, “200px”)
  $(‘#bam’).animate({ width: 300 })
}).trigger(‘click’);
Why not:
var clicker = function(){
    $(“#bam”)
     .addClass(“bar”)
     .css({ width:”200px” })
     .animate({ width:”300px” })
}
$(“#bar”).click(clicker);
clicker();
UBIQUITOUS
 “But can it run JavaScript?”
Device Penetration
Browsers, Now

  Desktop, Mobile, Device

Server

  Rhino

  V8

  Spidermonkey
Future Browsers?


Kitchen Crap

Televisions

Washer / Dryer?

...
COMMONJS
  is piggybacking.
CommonJS

Modules should be in the language, not here.

Forgot about the browser (see: Modules)

  Though has nothing to do with the DOM

A bit late?

  Only more time will tell.
STANDARDS.
 Yep. We (kinda) have them.
MDC: Array.prototype


Array.forEach / map / filter / indexOf / etc etc

  None of us handle sparse arrays to spec

  jQuery.map vs jQuery().map offends my senses

  dojo.map(ar, “return item * 2”) is too much magic
“Portability”

[1,2,3].forEach(function(item, index){ ... }, context);

dojo.forEach([1,2,3], function(item, index){ ... }, context);

jQuery.each([1,2,3], function(index){ /* this == item */ });

Y.Array.each([1,2,3], function(item, index){ ... }, context)

Fuse.win([1,2,3], function(item, index){ ... }, context);
MDC: Fn.proto.bind
                                        “this” is important.

var obj = {
     counter:0,
     inc: function(howmuch){ this.counter += howmuch || 0; }
};
var pfn = obj.inc.bind(obj, 5); // native, moo, proto way
var dfn = dojo.hitch(obj, “inc”, 5), // dojo
var dfn2 = dojo.hitch(obj, obj.inc, 5); // dojo is backwards
var jfn = jQuery.proxy(obj, “inc”); // so is jq. only w/ strings (also can’t pass args)
var jfn2 = jQuery.proxy(obj.inc, obj); // this is just plain inconsistent (no args here either)
I’M MISSING THE POINT?
       No, i’m not being clear.
Your library sucks, still.
I’m a grumpy old man. </rant>

No compelling reason for YOU not to use them

  If you understand what it’s doing

  If you don’t MIX

  Non-trivial tasks

  Portability
Library Benefits


Deferred development cost

  Open Source / Many Eyes

  Battle-tested

Common / Consistent APIs
I WANT TO CHANGE TOPICS
       Really. Let’s move forward, instead.
Propose: CommonBrowserJS
Reduce what we’ve learned over the years

Common Library to build upon

No Magic, Pure Standards

No UA sniffs, pure `feature detection`

Can load CommonJS modules/packages

Try to be agnostic? Back to Dojo beginnings.
Small Problems are Easy


MDC / ECMA standards are easy. What next?

  Modularity

  Stability (regressions, deprecation, sane versioning)

  Localization/Internationalization? (l10n, i18n)
First pass: has.js


Agnostic Core

pure Feature Detection framework

API not as important as converging on test implementations

Naming shit is hard.
DOJO ALREADY DID IT.
    @dojodidit - Really, We probably have.
DISCUSS.
Done talking. Ask questions if you like.
AAAAND THANKS.
#jsconfeu FTW, 2010 - enjoy the rest of the conference.
Me, again:

http://dante.dojotoolkit.org

http://higginsforpresident.net

http://twitter.com/phiggins

http://github.com/phiggins42

phiggins @ irc.freenode.net

More Related Content

PDF
Hubot: a look inside our robot friend
PDF
My Robot Poops - In JavaScript (with web sockets)
PDF
Plugin jQuery, Design Patterns
PDF
Making JavaScript Libraries More Approachable
PPTX
How to build a slack-hubot with js
PDF
JavaScript - Like a Box of Chocolates
ODP
Danny Adair - Python Cookbook - Intro
KEY
jQuery Plugin Creation
Hubot: a look inside our robot friend
My Robot Poops - In JavaScript (with web sockets)
Plugin jQuery, Design Patterns
Making JavaScript Libraries More Approachable
How to build a slack-hubot with js
JavaScript - Like a Box of Chocolates
Danny Adair - Python Cookbook - Intro
jQuery Plugin Creation

What's hot (20)

PDF
ATS language overview
ODP
NYPHP March 2009 Presentation
KEY
jQuery Anti-Patterns for Performance & Compression
ODP
Modern Perl
ODP
Moose - YAPC::NA 2012
PPTX
Troubleshooting Puppet
PDF
Getting Started With Puppet - Chad Metcalf
KEY
Beginner's Sinatra
ODP
Evolving Software with Moose
PDF
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
PDF
Barcelona 2010 hidden_features
PPTX
A Blink Into The Rails Magic
KEY
An introduction to Ruby
PDF
Introduction to CoffeeScript
PDF
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
PDF
Ruby - Uma Introdução
PDF
Trio of Gems
ODP
Tame your Infrastructure with Puppet
PDF
My Adventures In Objective-C (A Rubyists Perspective)
ATS language overview
NYPHP March 2009 Presentation
jQuery Anti-Patterns for Performance & Compression
Modern Perl
Moose - YAPC::NA 2012
Troubleshooting Puppet
Getting Started With Puppet - Chad Metcalf
Beginner's Sinatra
Evolving Software with Moose
Crystal: Fundamentos, objetivos y desafios - Cacic 2019
Barcelona 2010 hidden_features
A Blink Into The Rails Magic
An introduction to Ruby
Introduction to CoffeeScript
Dario Faggioli - Virtualization in the age of speculative execution HW bugs
Ruby - Uma Introdução
Trio of Gems
Tame your Infrastructure with Puppet
My Adventures In Objective-C (A Rubyists Perspective)
Ad

Similar to Your Library Sucks, and why you should use it. (20)

KEY
jQuery Anti-Patterns for Performance
KEY
JavaScript Growing Up
PDF
[FT-7][snowmantw] How to make a new functional language and make the world be...
PDF
Everything is Permitted: Extending Built-ins
PPTX
5 Tips for Better JavaScript
PDF
JavaOne 2013: Java 8 - The Good Parts
PDF
Java 8: the good parts!
PDF
Clipboard support on Y! mail
PDF
JavaScript ES6
PPTX
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
PPTX
All of javascript
KEY
Javascript unit testing, yes we can e big
PPT
JavaScript Basics
KEY
JavaScript Neednt Hurt - JavaBin talk
PPT
Javascript quiz. Questions to ask when recruiting developers.
PDF
Why Every Tester Should Learn Ruby
PDF
Building android apps with kotlin
PDF
Ember background basics
PPT
Demystifying Maven
jQuery Anti-Patterns for Performance
JavaScript Growing Up
[FT-7][snowmantw] How to make a new functional language and make the world be...
Everything is Permitted: Extending Built-ins
5 Tips for Better JavaScript
JavaOne 2013: Java 8 - The Good Parts
Java 8: the good parts!
Clipboard support on Y! mail
JavaScript ES6
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
All of javascript
Javascript unit testing, yes we can e big
JavaScript Basics
JavaScript Neednt Hurt - JavaBin talk
Javascript quiz. Questions to ask when recruiting developers.
Why Every Tester Should Learn Ruby
Building android apps with kotlin
Ember background basics
Demystifying Maven
Ad

More from Peter Higgins (9)

PDF
Jsconf.us.2013
PDF
has("builds")
PDF
PDF
Just JavaScript
KEY
PDF
dojo.things()
PDF
dojo.Patterns
PDF
Trimming The Cruft
PDF
Zero To Dojo
Jsconf.us.2013
has("builds")
Just JavaScript
dojo.things()
dojo.Patterns
Trimming The Cruft
Zero To Dojo

Recently uploaded (20)

PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Electronic commerce courselecture one. Pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Empathic Computing: Creating Shared Understanding
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
cuic standard and advanced reporting.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Building Integrated photovoltaic BIPV_UPV.pdf
Modernizing your data center with Dell and AMD
Electronic commerce courselecture one. Pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
A Presentation on Artificial Intelligence
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation_ Review paper, used for researhc scholars
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Empathic Computing: Creating Shared Understanding
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Monthly Chronicles - July 2025
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
cuic standard and advanced reporting.pdf

Your Library Sucks, and why you should use it.