SlideShare une entreprise Scribd logo
1  sur  38
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

Contenu connexe

Tendances

jQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & CompressionjQuery Anti-Patterns for Performance & Compression
jQuery Anti-Patterns for Performance & Compression
Paul Irish
 
Evolving Software with Moose
Evolving Software with MooseEvolving Software with Moose
Evolving Software with Moose
Dave Cross
 
Barcelona 2010 hidden_features
Barcelona 2010 hidden_featuresBarcelona 2010 hidden_features
Barcelona 2010 hidden_features
Anis Berejeb
 

Tendances (20)

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

Similaire à Your Library Sucks, and why you should use it.

JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
David Padbury
 
Javascript unit testing, yes we can e big
Javascript unit testing, yes we can   e bigJavascript unit testing, yes we can   e big
Javascript unit testing, yes we can e big
Andy Peterson
 

Similaire à Your Library Sucks, and why you should use it. (20)

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

Plus de Peter Higgins (9)

Jsconf.us.2013
Jsconf.us.2013Jsconf.us.2013
Jsconf.us.2013
 
has("builds")
has("builds")has("builds")
has("builds")
 
has.js
has.jshas.js
has.js
 
Just JavaScript
Just JavaScriptJust JavaScript
Just JavaScript
 
Txjs
TxjsTxjs
Txjs
 
dojo.things()
dojo.things()dojo.things()
dojo.things()
 
dojo.Patterns
dojo.Patternsdojo.Patterns
dojo.Patterns
 
Trimming The Cruft
Trimming The CruftTrimming The Cruft
Trimming The Cruft
 
Zero To Dojo
Zero To DojoZero To Dojo
Zero To Dojo
 

Dernier

Dernier (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Your Library Sucks, and why you should use it.

  • 1. YOUR LIBRARY SUCKS. jsconf.eu :: 25 Sept 2010 :: Peter Higgins
  • 2. BUT YOU SHOULD USE IT. jsconf.eu :: 25 Sept 2010 :: Peter Higgins
  • 3. 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
  • 4. It’s Just JavaScript TM Lovable, Simple Self Healing Promiscuous Ubiquitous
  • 5. The Good Parts Context :: apply/call/hitch/partial AOP, FTW. (duck punch...) Prototypes, also FTW Module Loading (/me jokes)
  • 6. The Bad Parts Date() :: designed with evil. The DOM :: also designed with evil. with() and eval() :: allegedly evil.
  • 7. Teh Libraries Dojo YUI Mootools / Prototype FuseJS (?) EmbedJS (?) jQuery Your own
  • 9. 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)
  • 10. PROMISCUOUS Also known as Loose Typing
  • 12. BASIC AOP <3 // I can fix anything: var oldfunction = some.oldFunction; some.oldFunction = function(){ oldfunction.apply(some, arguments); // closures, ftw. }
  • 13. 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 */ };
  • 14. 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); } }
  • 16. DON’T DO THIS: $(“div button#bar”).click(function(){ $(‘#bam’).addClass(“bar”); $(‘#bam’).css(“width”, “200px”) $(‘#bam’).animate({ width: “+=100” }) }).click();
  • 17. 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’);
  • 18. Why not: var clicker = function(){ $(“#bam”) .addClass(“bar”) .css({ width:”200px” }) .animate({ width:”300px” }) } $(“#bar”).click(clicker); clicker();
  • 19. UBIQUITOUS “But can it run JavaScript?”
  • 20. Device Penetration Browsers, Now Desktop, Mobile, Device Server Rhino V8 Spidermonkey
  • 22. COMMONJS is piggybacking.
  • 23. 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.
  • 24. STANDARDS. Yep. We (kinda) have them.
  • 25. 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
  • 26. “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);
  • 27. 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)
  • 28. I’M MISSING THE POINT? No, i’m not being clear.
  • 29. 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
  • 30. Library Benefits Deferred development cost Open Source / Many Eyes Battle-tested Common / Consistent APIs
  • 31. I WANT TO CHANGE TOPICS Really. Let’s move forward, instead.
  • 32. 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.
  • 33. Small Problems are Easy MDC / ECMA standards are easy. What next? Modularity Stability (regressions, deprecation, sane versioning) Localization/Internationalization? (l10n, i18n)
  • 34. First pass: has.js Agnostic Core pure Feature Detection framework API not as important as converging on test implementations Naming shit is hard.
  • 35. DOJO ALREADY DID IT. @dojodidit - Really, We probably have.
  • 36. DISCUSS. Done talking. Ask questions if you like.
  • 37. AAAAND THANKS. #jsconfeu FTW, 2010 - enjoy the rest of the conference.

Notes de l'éditeur