SlideShare una empresa de Scribd logo
1 de 132
Descargar para leer sin conexión
Secrets of Awesome JavaScript
API Design
Brandon Satrom
@BrandonSatrom
brandon@KendoUI.com
Read it @
bit.ly/
ZS5VYv
3Big Ideas
Three ideas...
Three ideas...
1.APIs are “Developer UX”
Three ideas...
1.APIs are “Developer UX”
2.API Design is a universal practice
Three ideas...
1.APIs are “Developer UX”
2.API Design is a universal practice
3.API Design is a “principle-driven” art form
What is design?
What is design?
“form[ing] a plan or scheme of [some
thing]… for later execution”
- Oxford English Dictionary
Design is universal
We judge designs to be...
...elegant
...beautiful
...utilitarian
...simple
...or not...
Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
We judge designs to be...
...elegant
...beautiful
...utilitarian
...simple
...or not...
Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
We judge designs to be...
...elegant
...beautiful
...utilitarian
...simple
...or not...
Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
We judge designs to be...
...elegant
...beautiful
...utilitarian
...simple
...or not...
Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
“Mediocre design provably wastes
the world’s resources, corrupts the
environment, affects international
competitiveness. Design is
important, teaching design is
important.”
- Fred Brooks
Image of Fred Brooks from: http://en.wikipedia.org/wiki/File:Fred_Brooks.jpg
Poor Design is Costly
We apply design practices
to User Interfaces...
Images from: http://pinterest.com/fromupnorth/gui/
We call this practice,
User Experience (UX)
design...
Images from: http://pinterest.com/fromupnorth/gui/
What about API Design?
API Design is “Developer UX”
API Design is not JUST For
Library Authors...
...modular JS is written to be
consumed...
...the number of
consumers is
irrelevant.
Images from flickr.com/photos/powi/
In JavaScript, API design is
critically important...
Dynamic Language...
Anonymity of
consumers...
http://i.qkme.me/3qesq1.jpg
Ambiguity of Requirements...
Your users are smart...
Yeah, but my
users won’t...
Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
Yeah, but my
users won’t...
Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
A Tale of Ice &
Water
A Tale of Ice &
Water
A Tale of Ice &
Water
A Tale of Ice &
Water
A Tale of Ice &
Water
In Industrial
Design, this is
NOT an
acceptable
answer...
Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
... how is Software Different?
Image from: http://www.globalnerdy.com/wordpress/wp-content/uploads/2010/05/makeabetterfm.jpg
... how is Software Different?
Image from: http://www.globalnerdy.com/wordpress/wp-content/uploads/2010/05/makeabetterfm.jpg
It’s Not.
Your users are smart...
http://thebus.net/sites/default/files/americas-next-top-hipster.jpg
...but they are NOT...
you.
http://thebus.net/sites/default/files/americas-next-top-hipster.jpg
Design the “pit of success”
Image from: http://darrell.mozingo.net/2011/06/26/the-pit-of-success/
Example:
$("article.blogPost").fadeIn();
Use jQuery to select all article tags with the class “blogPost”
Example:
$("article.blogPost").fadeIn();
Use jQuery to select all article tags with the class “blogPost”
article.blogPost	
  {
	
  	
  border-­‐radius:	
  10px;
	
  	
  background-­‐color:	
  salmon;
	
  	
  box-­‐shadow:	
  0px	
  0px	
  10px	
  2px	
  #ccc;
}
Goals of API Design
Be Self-Describing
Prevent Errors
Make Users Fast
Image from: http://elliottbrown.files.wordpress.com/2012/04/sandcastles.png
Goals are not enough...
...we need guiding principles...
Principles, not Rules
Principles, not Rules
Rules are rote, often applied without context
Principles encourage application of context
Principles Found in Physical Media
Images from: http://char.txa.cornell.edu/language/principl/principl.htm & http://www.greatbuildings.com/
Principles on display in popular
libraries...
Backbone
jQuery
Kendo UI
Modernizr
Moment.js
Underscore
The Four Principles
Unity & Harmony
Balance
Proportion
Emphasis
WARNING! This is ART, not
SCIENCE
Unity and Harmony
Image “Portrait of the children of Charles I” by Anthony Van Dyck from: http://char.txa.cornell.edu/language/principl/principl.htm
Unity and
Harmony (art)
Unity: The concept behind a work, or how the composer brings
everything together into a coherent whole.
Harmony: The placement of similar elements throughout a work,
yielding an uncomplicated and simple feel.
Painting by Robert Delauny, from: http://char.txa.cornell.edu/language/principl/principl.htm
Unity & Harmony (API Design):
Familiarity & Comfort
Extended Object creation in
Backbone
Widget Instantiation in
Kendo UI
Use similar and/or
unifying elements
through your library
to create familiarity
and comfort
Example:
Create Kendo UI Widgets from jQuery-selected DOM Elements
$("ul.tree").kendoTreeView();
$("ul.panel").kendoPanelBar();
$("div").kendoGrid();
Example:
Create Kendo UI Widgets from jQuery-selected DOM Elements
Each Widget is prefixed
with “kendo” and named in
a consistent, camel-cased
style
$("ul.tree").kendoTreeView();
$("ul.panel").kendoPanelBar();
$("div").kendoGrid();
Example:
Create Extended Objects with Backbone
var	
  Book	
  =	
  Backbone.Model.extend({
	
  	
  initialize:	
  function()	
  {	
  ...	
  },
	
  	
  author:	
  function()	
  {	
  ...	
  },
	
  	
  pubDate:	
  function()	
  {	
  ...	
  },
});
var	
  DocumentRow	
  =	
  Backbone.View.extend({
	
  	
  tagName:	
  "li",
	
  	
  className:	
  "row",
	
  	
  events:	
  {
	
  	
  	
  	
  "click	
  .icon":	
  "open",
	
  	
  	
  	
  "click	
  .button.edit":	
  "openEditDialog"
	
  	
  },
	
  	
  render:	
  function()	
  {	
  ...	
  }
});
Example:
Create Extended Objects with Backbone
[Object].extend is used to
“inherit” the built-in
functionality of Backbone
Models, Views, Collections
and Routers
var	
  Book	
  =	
  Backbone.Model.extend({
	
  	
  initialize:	
  function()	
  {	
  ...	
  },
	
  	
  author:	
  function()	
  {	
  ...	
  },
	
  	
  pubDate:	
  function()	
  {	
  ...	
  },
});
var	
  DocumentRow	
  =	
  Backbone.View.extend({
	
  	
  tagName:	
  "li",
	
  	
  className:	
  "row",
	
  	
  events:	
  {
	
  	
  	
  	
  "click	
  .icon":	
  "open",
	
  	
  	
  	
  "click	
  .button.edit":	
  "openEditDialog"
	
  	
  },
	
  	
  render:	
  function()	
  {	
  ...	
  }
});
Balance
Image “Portrait of the children of Charles I” by Anthony Van Dyck from: http://char.txa.cornell.edu/language/principl/principl.htm
Balance (art)
The arrangement of elements to ensure that no one part of the work
overpowers other parts, or causes it to feel unstable.
Image of Italian Textile, 18th Centuty from: http://char.txa.cornell.edu/language/principl/principl.htm
Balance (API Design):
Weight & Predictability
Browser Feature Tests in
Modernizr
DOM Selection Syntax in
jQuery
Ensure that each
function of your
library exhibits
consistent behavior,
or aids in meeting a
complimentary goal.
Example:
Modernizr.geolocation
Modernizr.localstorage
Modernizr.webworkers
Modernizr.canvas
Modernizr.borderradius
Test Browser Capabilities using Modernizr
Example:
Modernizr.geolocation
Modernizr.localstorage
Modernizr.webworkers
Modernizr.canvas
Modernizr.borderradius
Test Browser Capabilities using Modernizr
Each property matches an
HTML5/CSS-related API
and returns a boolean
Example:
$("#grid")	
  //	
  Selects	
  by	
  ID
$("ul.nav	
  >	
  li")	
  //	
  All	
  LIs	
  for	
  UL	
  w/class	
  "nav"
$("ul	
  li:nth-­‐child(2)")	
  //	
  2nd	
  item	
  in	
  each	
  list
Select DOM Elements using jQuery’s Selector Syntax
Example:
$("#grid")	
  //	
  Selects	
  by	
  ID
$("ul.nav	
  >	
  li")	
  //	
  All	
  LIs	
  for	
  UL	
  w/class	
  "nav"
$("ul	
  li:nth-­‐child(2)")	
  //	
  2nd	
  item	
  in	
  each	
  list
Select DOM Elements using jQuery’s Selector Syntax
Many jQuery Selectors
map directly to equivalent
CSS selectors
Proportion
Image “The Fisherman” by Saul Steinberg from: http://char.txa.cornell.edu/language/principl/principl.htm
Proportion (art)
A measurement of the size and quantity of elements within a work,
relative to the whole.
Image of Salisbury Cathedral from: http://char.txa.cornell.edu/language/principl/principl.htm
Proportion (API Design):
Scope that matches capability
Moment.js
Underscore
Make sure that
every interface of
the library matches
its intended purpose
& that no extraneous
elements exist.
Example:
Moment.js is working working with dates... and that’s it
moment().format('dddd');
moment().startOf('hour').fromNow();
moment().format('[Hello from] YYYY'); // Hello from 2013
moment().startOf('day').fromNow();
Example:
Moment.js is working working with dates... and that’s it
Moment is designed to make working with the
JavaScript Date object tolerable, and it provides
no functionality beyond that scope.
moment().format('dddd');
moment().startOf('hour').fromNow();
moment().format('[Hello from] YYYY'); // Hello from 2013
moment().startOf('day').fromNow();
_.each(["Todd",	
  "Burke",	
  "Derick"],	
  function(name){	
  
	
  	
  alert(name);	
  
});
_.map([1,	
  2,	
  3],	
  function(num){	
  
	
  	
  return	
  num	
  *	
  3;	
  
});
_.isNumber("ten");	
  //	
  False
Example:
Underscore.js, designed to add functional programming support to JS
_.each(["Todd",	
  "Burke",	
  "Derick"],	
  function(name){	
  
	
  	
  alert(name);	
  
});
_.map([1,	
  2,	
  3],	
  function(num){	
  
	
  	
  return	
  num	
  *	
  3;	
  
});
_.isNumber("ten");	
  //	
  False
Example:
Underscore.js, designed to add functional programming support to JS
Underscore provides utility
functions that help devs work
with JS collections, arrays,
functions and objects. Larger API
surface, for a broader purpose.
Emphasis
Image of the FlatIron Building from: http://www.greatbuildings.com/
Emphasis (art)
The point of focus or interruption of a work. The use of contrast to
cause an aspect of the work to stand out and capture the viewer’s
attention.
Image from: http://char.txa.cornell.edu/language/principl/principl.htm
Emphasis (API Design):
Creating a focal point
Plugin development using
jQuery’s fn namespace
Method chaining in jQuery
Object extensibility in
Backbone
Provide a gateway
method that anchors
your library, a chained
or fluent API, or create
extensibility hooks for
consuming devs
Example:
jQuery enables a fluent programming style by returning a
jQuery object from most functions.
$(‘ul.first’).find(‘.overdue’)
	
  	
  .css(‘background-­‐color’,‘red’)
	
  	
  .end()
	
  	
  .find(‘.due-­‐soon’)
	
  	
  .css(‘background-­‐color’,	
  ‘yellow’);
Example:
jQuery enables a fluent programming style by returning a
jQuery object from most functions.
This style enables devs to accomplish a great
deal of work in a terse, yet readable manner.
$(‘ul.first’).find(‘.overdue’)
	
  	
  .css(‘background-­‐color’,‘red’)
	
  	
  .end()
	
  	
  .find(‘.due-­‐soon’)
	
  	
  .css(‘background-­‐color’,	
  ‘yellow’);
(function($)	
  {
	
  	
  $.fn.kittehfy	
  =	
  function()	
  {
	
  	
  	
  	
  return	
  this.each(function(idx,	
  el)	
  {	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  var	
  width	
  =	
  el.width,
	
  	
  	
  	
  	
  	
  	
  	
  height	
  =	
  el.height;
	
  	
  	
  	
  	
  	
  var	
  src=	
  "http://placekitten.com/";
	
  	
  	
  	
  	
  	
  el.src=	
  src	
  +	
  width	
  +	
  "/"	
  +	
  height;
	
  	
  	
  	
  });
	
  	
  };
})(jQuery);
$("img").kittehfy();
Example:
jQuery plugins are connected to jQuery via the fn (“effin”)
namespace...
(function($)	
  {
	
  	
  $.fn.kittehfy	
  =	
  function()	
  {
	
  	
  	
  	
  return	
  this.each(function(idx,	
  el)	
  {	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  var	
  width	
  =	
  el.width,
	
  	
  	
  	
  	
  	
  	
  	
  height	
  =	
  el.height;
	
  	
  	
  	
  	
  	
  var	
  src=	
  "http://placekitten.com/";
	
  	
  	
  	
  	
  	
  el.src=	
  src	
  +	
  width	
  +	
  "/"	
  +	
  height;
	
  	
  	
  	
  });
	
  	
  };
})(jQuery);
$("img").kittehfy();
Example:
jQuery plugins are connected to jQuery via the fn (“effin”)
namespace...
jQuery Plugins “feel” like
natural extensions to
jQuery itself, and behave
in similar ways
Example:
	
  	
  
var	
  Book	
  =	
  Backbone.Model.extend({	
  	
  
	
  	
  initialize:	
  function()	
  {	
  ...	
  },
	
  	
  author:	
  function()	
  {	
  ...	
  },
	
  	
  pubDate:	
  function()	
  {	
  ...	
  },
});
var	
  DocumentRow	
  =	
  Backbone.View.extend({
	
  	
  tagName:	
  "li",
	
  	
  className:	
  "row",
	
  	
  events:	
  {
	
  	
  	
  	
  "click	
  .icon":	
  "open",
	
  	
  	
  	
  "click	
  .button.edit":	
  "openEditDialog"
	
  	
  },
	
  	
  render:	
  function()	
  {	
  ...	
  }
});
Create Extended Objects with Backbone
Example:
	
  	
  
var	
  Book	
  =	
  Backbone.Model.extend({	
  	
  
	
  	
  initialize:	
  function()	
  {	
  ...	
  },
	
  	
  author:	
  function()	
  {	
  ...	
  },
	
  	
  pubDate:	
  function()	
  {	
  ...	
  },
});
var	
  DocumentRow	
  =	
  Backbone.View.extend({
	
  	
  tagName:	
  "li",
	
  	
  className:	
  "row",
	
  	
  events:	
  {
	
  	
  	
  	
  "click	
  .icon":	
  "open",
	
  	
  	
  	
  "click	
  .button.edit":	
  "openEditDialog"
	
  	
  },
	
  	
  render:	
  function()	
  {	
  ...	
  }
});
Create Extended Objects with Backbone
[Object].extend is used to
“inherit” the built-in
functionality of Backbone
Models, Views, Collections
and Routers
The Four Principles
Unity & Harmony
Balance
Proportion
Emphasis
The HORROR!
aka What might go wrong...
What might go wrong...
Inconsistency
Disproportionality
Imbalance...
Callback signatures on $.map, $.each & $(el).map
Imbalance...
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
var	
  uppers	
  =	
  $.map(letters,	
  function(val,	
  index)	
  {
	
  	
  return	
  (val.toUpperCase());
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
var	
  uppers	
  =	
  $.map(letters,	
  function(val,	
  index)	
  {
	
  	
  return	
  (val.toUpperCase());
});
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
var	
  uppers	
  =	
  $.map(letters,	
  function(val,	
  index)	
  {
	
  	
  return	
  (val.toUpperCase());
});
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
var	
  uppers	
  =	
  $.map(letters,	
  function(val,	
  index)	
  {
	
  	
  return	
  (val.toUpperCase());
});
$(‘li’).map(function(index,	
  val)	
  {	
  //WAT	
  });
Callback signatures on $.map, $.each & $(el).map
Imbalance...
var	
  letters	
  =	
  [“a”,	
  “b”,	
  “c”,	
  “d”,	
  “e”];
$.each(letters,	
  function(index,	
  val)	
  {
	
  	
  console.log(index	
  +	
  “:	
  “	
  +	
  val.toUpperCase());
});	
  
var	
  uppers	
  =	
  $.map(letters,	
  function(val,	
  index)	
  {
	
  	
  return	
  (val.toUpperCase());
});
$(‘li’).map(function(index,	
  val)	
  {	
  //WAT	
  });
Callback signatures on $.map, $.each & $(el).map
Not only do $.map and $.each diverge, but $.map and $(el).map order the
callback params differently, depending on how the method is called.
Proportion: Too
Large or Too Small...
Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
“Van der Poel designed a computer with only
one operation code...”
Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
“... Every instruction carried out the same
operation. He demonstrated the sufficiency of
his operation—his machine could do anything
any other computer could do...”
Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
“...And yet it was very difficult to program....”
Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
“...the delight that came from using it was
similar to... working out a crossword puzzle—
a construct of intentional complexity and no
intended utility.”
- Fred Brooks
AwesomeLib.do(prams);
AwesomeLib.do(prams);
We can all agree
that this is bad
jQuery();
jQuery();
Then, so is this...
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
jQuery(	
  	
  jQuery	
  object	
  )	
  //	
  Clone
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
jQuery(	
  	
  jQuery	
  object	
  )	
  //	
  Clone
jQuery(	
  html	
  [,	
  ownerDocument	
  ]	
  )	
  //	
  Create	
  DOM	
  Elements
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
jQuery(	
  	
  jQuery	
  object	
  )	
  //	
  Clone
jQuery(	
  html	
  [,	
  ownerDocument	
  ]	
  )	
  //	
  Create	
  DOM	
  Elements
jQuery	
  (	
  html,	
  props	
  )	
  //	
  Create	
  DOM	
  Elements
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
jQuery(	
  	
  jQuery	
  object	
  )	
  //	
  Clone
jQuery(	
  html	
  [,	
  ownerDocument	
  ]	
  )	
  //	
  Create	
  DOM	
  Elements
jQuery	
  (	
  html,	
  props	
  )	
  //	
  Create	
  DOM	
  Elements
jQuery	
  (	
  callback	
  )	
  //	
  Bind	
  DOM	
  loaded	
  function	
  
Overloads on the jQuery()
method...
jQuery(	
  selector	
  [,	
  context]	
  )	
  //	
  Select
jQuery(	
  element	
  )	
  //	
  Wrap
jQuery(	
  object	
  )	
  //	
  Wrap
jQuery()	
  //	
  Empty	
  $	
  Object
jQuery(	
  elementArray	
  )	
  //	
  Wrap
jQuery(	
  	
  jQuery	
  object	
  )	
  //	
  Clone
jQuery(	
  html	
  [,	
  ownerDocument	
  ]	
  )	
  //	
  Create	
  DOM	
  Elements
jQuery	
  (	
  html,	
  props	
  )	
  //	
  Create	
  DOM	
  Elements
jQuery	
  (	
  callback	
  )	
  //	
  Bind	
  DOM	
  loaded	
  function	
  
Overloads on the jQuery()
method...
11 ways to call
jQuery, with 6
different contexts!
Now, for a question...
jQuery: Good
API Design or
Bad API
Design?
Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
jQuery: Good
API Design or
Bad API
Design?
Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
A baseline example of “Good...”
jQuery: Good
API Design or
Bad API
Design?
Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
A baseline example of “Good...”
YES
Here’s the
point...
Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
Building and
evolving a useful
API is hard...
Image from: http://www.ibiblio.org/xml/slides/xmlone/london2002/schemas/83.html
...you won’t always
get it right.
Image from: gorestruly.com2011/09/30/rotting-americana-the-winchester-mystery-house/
But hey, jQuery’s not perfect...
... so you don’t have to be either.
Questions?
@BrandonSatrom
brandon@kendoui.com

Más contenido relacionado

La actualidad más candente

Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesSimon Willison
 
JavaScript!
JavaScript!JavaScript!
JavaScript!RTigger
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说Ting Lv
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Railsshen liu
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingDoug Neiner
 
JavaScript Prototype and Module Pattern
JavaScript Prototype and Module PatternJavaScript Prototype and Module Pattern
JavaScript Prototype and Module PatternNarendra Sisodiya
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Filippo Matteo Riggio
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j queryMd. Ziaul Haq
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitRebecca Murphey
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With RailsBoris Nadion
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyHuiyi Yan
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptPeter-Paul Koch
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendFITC
 
2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritancepedro.carvalho
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuerycolinbdclark
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery ApplicationsRebecca Murphey
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Chris Alfano
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.jsBert Wijnants
 

La actualidad más candente (20)

Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
Rediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The LibrariesRediscovering JavaScript: The Language Behind The Libraries
Rediscovering JavaScript: The Language Behind The Libraries
 
JavaScript!
JavaScript!JavaScript!
JavaScript!
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Jquery In Rails
Jquery In RailsJquery In Rails
Jquery In Rails
 
jQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and BlingjQuery: Nuts, Bolts and Bling
jQuery: Nuts, Bolts and Bling
 
JavaScript Prototype and Module Pattern
JavaScript Prototype and Module PatternJavaScript Prototype and Module Pattern
JavaScript Prototype and Module Pattern
 
Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2Mobile App Development: Primi passi con NativeScript e Angular 2
Mobile App Development: Primi passi con NativeScript e Angular 2
 
Kick start with j query
Kick start with j queryKick start with j query
Kick start with j query
 
Mulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development ToolkitMulberry: A Mobile App Development Toolkit
Mulberry: A Mobile App Development Toolkit
 
Dojo Confessions
Dojo ConfessionsDojo Confessions
Dojo Confessions
 
Web Components With Rails
Web Components With RailsWeb Components With Rails
Web Components With Rails
 
jQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journeyjQuery Data Manipulate API - A source code dissecting journey
jQuery Data Manipulate API - A source code dissecting journey
 
An Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScriptAn Event Apart Boston: Principles of Unobtrusive JavaScript
An Event Apart Boston: Principles of Unobtrusive JavaScript
 
CSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the BackendCSS: A Slippery Slope to the Backend
CSS: A Slippery Slope to the Backend
 
2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance2012 oct-12 - java script inheritance
2012 oct-12 - java script inheritance
 
User Interface Development with jQuery
User Interface Development with jQueryUser Interface Development with jQuery
User Interface Development with jQuery
 
Building Large jQuery Applications
Building Large jQuery ApplicationsBuilding Large jQuery Applications
Building Large jQuery Applications
 
Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011Jarv.us Showcase — SenchaCon 2011
Jarv.us Showcase — SenchaCon 2011
 
Viking academy backbone.js
Viking academy  backbone.jsViking academy  backbone.js
Viking academy backbone.js
 

Similar a Secrets of Awesome JavaScript API Design

Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmersAlexander Varwijk
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
Come abbiamo scalato Dazn con micro-architetture
Come abbiamo scalato Dazn con micro-architettureCome abbiamo scalato Dazn con micro-architetture
Come abbiamo scalato Dazn con micro-architettureCommit University
 
Techorama 2019 - ASP.NET Core One Hour Makeover
Techorama 2019 - ASP.NET Core One Hour MakeoverTechorama 2019 - ASP.NET Core One Hour Makeover
Techorama 2019 - ASP.NET Core One Hour MakeoverJon Galloway
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsEPAM Systems
 
Everything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLIEverything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLIAmadou Sall
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery LearningUzair Ali
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.jsreybango
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureSimon Willison
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom componentsJeremy Grancher
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Againjonknapp
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 

Similar a Secrets of Awesome JavaScript API Design (20)

jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
Jquery
JqueryJquery
Jquery
 
lecture5
lecture5lecture5
lecture5
 
lecture5
lecture5lecture5
lecture5
 
Multilingualism makes better programmers
Multilingualism makes better programmersMultilingualism makes better programmers
Multilingualism makes better programmers
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
Come abbiamo scalato Dazn con micro-architetture
Come abbiamo scalato Dazn con micro-architettureCome abbiamo scalato Dazn con micro-architetture
Come abbiamo scalato Dazn con micro-architetture
 
Techorama 2019 - ASP.NET Core One Hour Makeover
Techorama 2019 - ASP.NET Core One Hour MakeoverTechorama 2019 - ASP.NET Core One Hour Makeover
Techorama 2019 - ASP.NET Core One Hour Makeover
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Jquery beltranhomewrok
Jquery beltranhomewrokJquery beltranhomewrok
Jquery beltranhomewrok
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Everything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLIEverything You Should Know About the New Angular CLI
Everything You Should Know About the New Angular CLI
 
jQuery Learning
jQuery LearningjQuery Learning
jQuery Learning
 
Getting into ember.js
Getting into ember.jsGetting into ember.js
Getting into ember.js
 
JavaScript Libraries: The Big Picture
JavaScript Libraries: The Big PictureJavaScript Libraries: The Big Picture
JavaScript Libraries: The Big Picture
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
From Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) AgainFrom Backbone to Ember and Back(bone) Again
From Backbone to Ember and Back(bone) Again
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
jQuery UI and Plugins
jQuery UI and PluginsjQuery UI and Plugins
jQuery UI and Plugins
 
jQuery
jQueryjQuery
jQuery
 

Más de Brandon Satrom

Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesBrandon Satrom
 
Coding the right thing
Coding the right thingCoding the right thing
Coding the right thingBrandon Satrom
 
Keeping architectures relevant
Keeping architectures relevantKeeping architectures relevant
Keeping architectures relevantBrandon Satrom
 
Workflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingWorkflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingBrandon Satrom
 
The Future Of Work And Workflow
The Future Of Work And WorkflowThe Future Of Work And Workflow
The Future Of Work And WorkflowBrandon Satrom
 

Más de Brandon Satrom (6)

Coffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotesCoffee scriptisforclosers nonotes
Coffee scriptisforclosers nonotes
 
Coding the right thing
Coding the right thingCoding the right thing
Coding the right thing
 
Workflow systems
Workflow systemsWorkflow systems
Workflow systems
 
Keeping architectures relevant
Keeping architectures relevantKeeping architectures relevant
Keeping architectures relevant
 
Workflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingWorkflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful Thinking
 
The Future Of Work And Workflow
The Future Of Work And WorkflowThe Future Of Work And Workflow
The Future Of Work And Workflow
 

Último

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusZilliz
 
"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 ...Zilliz
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbuapidays
 
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 FresherRemote DBA Services
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
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...apidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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...Zilliz
 
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 CVKhem
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
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].pdfOverkill Security
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...apidays
 

Último (20)

A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
"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 ...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
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
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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...
 
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
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 

Secrets of Awesome JavaScript API Design

  • 1. Secrets of Awesome JavaScript API Design Brandon Satrom @BrandonSatrom brandon@KendoUI.com
  • 5. Three ideas... 1.APIs are “Developer UX”
  • 6. Three ideas... 1.APIs are “Developer UX” 2.API Design is a universal practice
  • 7. Three ideas... 1.APIs are “Developer UX” 2.API Design is a universal practice 3.API Design is a “principle-driven” art form
  • 9. What is design? “form[ing] a plan or scheme of [some thing]… for later execution” - Oxford English Dictionary
  • 11. We judge designs to be... ...elegant ...beautiful ...utilitarian ...simple ...or not... Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
  • 12. We judge designs to be... ...elegant ...beautiful ...utilitarian ...simple ...or not... Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
  • 13. We judge designs to be... ...elegant ...beautiful ...utilitarian ...simple ...or not... Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
  • 14. We judge designs to be... ...elegant ...beautiful ...utilitarian ...simple ...or not... Images from: http://www.greatbuildings.com/ and http://list25.com/25-ugliest-buildings-in-the-world/
  • 15. “Mediocre design provably wastes the world’s resources, corrupts the environment, affects international competitiveness. Design is important, teaching design is important.” - Fred Brooks Image of Fred Brooks from: http://en.wikipedia.org/wiki/File:Fred_Brooks.jpg Poor Design is Costly
  • 16. We apply design practices to User Interfaces... Images from: http://pinterest.com/fromupnorth/gui/
  • 17. We call this practice, User Experience (UX) design... Images from: http://pinterest.com/fromupnorth/gui/
  • 18. What about API Design?
  • 19. API Design is “Developer UX”
  • 20. API Design is not JUST For Library Authors...
  • 21. ...modular JS is written to be consumed...
  • 22. ...the number of consumers is irrelevant. Images from flickr.com/photos/powi/
  • 23. In JavaScript, API design is critically important...
  • 27. Your users are smart...
  • 28. Yeah, but my users won’t... Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
  • 29. Yeah, but my users won’t... Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
  • 30. A Tale of Ice & Water
  • 31. A Tale of Ice & Water
  • 32. A Tale of Ice & Water
  • 33. A Tale of Ice & Water
  • 34. A Tale of Ice & Water
  • 35. In Industrial Design, this is NOT an acceptable answer... Image from: http://idratherbewriting.com/wp-content/uploads/2012/08/rtfmtractor.jpg
  • 36. ... how is Software Different? Image from: http://www.globalnerdy.com/wordpress/wp-content/uploads/2010/05/makeabetterfm.jpg
  • 37. ... how is Software Different? Image from: http://www.globalnerdy.com/wordpress/wp-content/uploads/2010/05/makeabetterfm.jpg It’s Not.
  • 38.
  • 39. Your users are smart...
  • 41. ...but they are NOT... you. http://thebus.net/sites/default/files/americas-next-top-hipster.jpg
  • 42. Design the “pit of success” Image from: http://darrell.mozingo.net/2011/06/26/the-pit-of-success/
  • 43. Example: $("article.blogPost").fadeIn(); Use jQuery to select all article tags with the class “blogPost”
  • 44. Example: $("article.blogPost").fadeIn(); Use jQuery to select all article tags with the class “blogPost” article.blogPost  {    border-­‐radius:  10px;    background-­‐color:  salmon;    box-­‐shadow:  0px  0px  10px  2px  #ccc; }
  • 45. Goals of API Design Be Self-Describing Prevent Errors Make Users Fast Image from: http://elliottbrown.files.wordpress.com/2012/04/sandcastles.png
  • 46.
  • 47. Goals are not enough...
  • 48.
  • 49. ...we need guiding principles...
  • 51. Principles, not Rules Rules are rote, often applied without context Principles encourage application of context
  • 52. Principles Found in Physical Media Images from: http://char.txa.cornell.edu/language/principl/principl.htm & http://www.greatbuildings.com/
  • 53. Principles on display in popular libraries... Backbone jQuery Kendo UI Modernizr Moment.js Underscore
  • 54. The Four Principles Unity & Harmony Balance Proportion Emphasis
  • 55. WARNING! This is ART, not SCIENCE
  • 56. Unity and Harmony Image “Portrait of the children of Charles I” by Anthony Van Dyck from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 57. Unity and Harmony (art) Unity: The concept behind a work, or how the composer brings everything together into a coherent whole. Harmony: The placement of similar elements throughout a work, yielding an uncomplicated and simple feel. Painting by Robert Delauny, from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 58. Unity & Harmony (API Design): Familiarity & Comfort Extended Object creation in Backbone Widget Instantiation in Kendo UI Use similar and/or unifying elements through your library to create familiarity and comfort
  • 59. Example: Create Kendo UI Widgets from jQuery-selected DOM Elements $("ul.tree").kendoTreeView(); $("ul.panel").kendoPanelBar(); $("div").kendoGrid();
  • 60. Example: Create Kendo UI Widgets from jQuery-selected DOM Elements Each Widget is prefixed with “kendo” and named in a consistent, camel-cased style $("ul.tree").kendoTreeView(); $("ul.panel").kendoPanelBar(); $("div").kendoGrid();
  • 61. Example: Create Extended Objects with Backbone var  Book  =  Backbone.Model.extend({    initialize:  function()  {  ...  },    author:  function()  {  ...  },    pubDate:  function()  {  ...  }, }); var  DocumentRow  =  Backbone.View.extend({    tagName:  "li",    className:  "row",    events:  {        "click  .icon":  "open",        "click  .button.edit":  "openEditDialog"    },    render:  function()  {  ...  } });
  • 62. Example: Create Extended Objects with Backbone [Object].extend is used to “inherit” the built-in functionality of Backbone Models, Views, Collections and Routers var  Book  =  Backbone.Model.extend({    initialize:  function()  {  ...  },    author:  function()  {  ...  },    pubDate:  function()  {  ...  }, }); var  DocumentRow  =  Backbone.View.extend({    tagName:  "li",    className:  "row",    events:  {        "click  .icon":  "open",        "click  .button.edit":  "openEditDialog"    },    render:  function()  {  ...  } });
  • 63. Balance Image “Portrait of the children of Charles I” by Anthony Van Dyck from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 64. Balance (art) The arrangement of elements to ensure that no one part of the work overpowers other parts, or causes it to feel unstable. Image of Italian Textile, 18th Centuty from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 65. Balance (API Design): Weight & Predictability Browser Feature Tests in Modernizr DOM Selection Syntax in jQuery Ensure that each function of your library exhibits consistent behavior, or aids in meeting a complimentary goal.
  • 68. Example: $("#grid")  //  Selects  by  ID $("ul.nav  >  li")  //  All  LIs  for  UL  w/class  "nav" $("ul  li:nth-­‐child(2)")  //  2nd  item  in  each  list Select DOM Elements using jQuery’s Selector Syntax
  • 69. Example: $("#grid")  //  Selects  by  ID $("ul.nav  >  li")  //  All  LIs  for  UL  w/class  "nav" $("ul  li:nth-­‐child(2)")  //  2nd  item  in  each  list Select DOM Elements using jQuery’s Selector Syntax Many jQuery Selectors map directly to equivalent CSS selectors
  • 70. Proportion Image “The Fisherman” by Saul Steinberg from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 71. Proportion (art) A measurement of the size and quantity of elements within a work, relative to the whole. Image of Salisbury Cathedral from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 72. Proportion (API Design): Scope that matches capability Moment.js Underscore Make sure that every interface of the library matches its intended purpose & that no extraneous elements exist.
  • 73. Example: Moment.js is working working with dates... and that’s it moment().format('dddd'); moment().startOf('hour').fromNow(); moment().format('[Hello from] YYYY'); // Hello from 2013 moment().startOf('day').fromNow();
  • 74. Example: Moment.js is working working with dates... and that’s it Moment is designed to make working with the JavaScript Date object tolerable, and it provides no functionality beyond that scope. moment().format('dddd'); moment().startOf('hour').fromNow(); moment().format('[Hello from] YYYY'); // Hello from 2013 moment().startOf('day').fromNow();
  • 75. _.each(["Todd",  "Burke",  "Derick"],  function(name){      alert(name);   }); _.map([1,  2,  3],  function(num){      return  num  *  3;   }); _.isNumber("ten");  //  False Example: Underscore.js, designed to add functional programming support to JS
  • 76. _.each(["Todd",  "Burke",  "Derick"],  function(name){      alert(name);   }); _.map([1,  2,  3],  function(num){      return  num  *  3;   }); _.isNumber("ten");  //  False Example: Underscore.js, designed to add functional programming support to JS Underscore provides utility functions that help devs work with JS collections, arrays, functions and objects. Larger API surface, for a broader purpose.
  • 77. Emphasis Image of the FlatIron Building from: http://www.greatbuildings.com/
  • 78. Emphasis (art) The point of focus or interruption of a work. The use of contrast to cause an aspect of the work to stand out and capture the viewer’s attention. Image from: http://char.txa.cornell.edu/language/principl/principl.htm
  • 79. Emphasis (API Design): Creating a focal point Plugin development using jQuery’s fn namespace Method chaining in jQuery Object extensibility in Backbone Provide a gateway method that anchors your library, a chained or fluent API, or create extensibility hooks for consuming devs
  • 80. Example: jQuery enables a fluent programming style by returning a jQuery object from most functions. $(‘ul.first’).find(‘.overdue’)    .css(‘background-­‐color’,‘red’)    .end()    .find(‘.due-­‐soon’)    .css(‘background-­‐color’,  ‘yellow’);
  • 81. Example: jQuery enables a fluent programming style by returning a jQuery object from most functions. This style enables devs to accomplish a great deal of work in a terse, yet readable manner. $(‘ul.first’).find(‘.overdue’)    .css(‘background-­‐color’,‘red’)    .end()    .find(‘.due-­‐soon’)    .css(‘background-­‐color’,  ‘yellow’);
  • 82. (function($)  {    $.fn.kittehfy  =  function()  {        return  this.each(function(idx,  el)  {                            var  width  =  el.width,                height  =  el.height;            var  src=  "http://placekitten.com/";            el.src=  src  +  width  +  "/"  +  height;        });    }; })(jQuery); $("img").kittehfy(); Example: jQuery plugins are connected to jQuery via the fn (“effin”) namespace...
  • 83. (function($)  {    $.fn.kittehfy  =  function()  {        return  this.each(function(idx,  el)  {                            var  width  =  el.width,                height  =  el.height;            var  src=  "http://placekitten.com/";            el.src=  src  +  width  +  "/"  +  height;        });    }; })(jQuery); $("img").kittehfy(); Example: jQuery plugins are connected to jQuery via the fn (“effin”) namespace... jQuery Plugins “feel” like natural extensions to jQuery itself, and behave in similar ways
  • 84. Example:     var  Book  =  Backbone.Model.extend({        initialize:  function()  {  ...  },    author:  function()  {  ...  },    pubDate:  function()  {  ...  }, }); var  DocumentRow  =  Backbone.View.extend({    tagName:  "li",    className:  "row",    events:  {        "click  .icon":  "open",        "click  .button.edit":  "openEditDialog"    },    render:  function()  {  ...  } }); Create Extended Objects with Backbone
  • 85. Example:     var  Book  =  Backbone.Model.extend({        initialize:  function()  {  ...  },    author:  function()  {  ...  },    pubDate:  function()  {  ...  }, }); var  DocumentRow  =  Backbone.View.extend({    tagName:  "li",    className:  "row",    events:  {        "click  .icon":  "open",        "click  .button.edit":  "openEditDialog"    },    render:  function()  {  ...  } }); Create Extended Objects with Backbone [Object].extend is used to “inherit” the built-in functionality of Backbone Models, Views, Collections and Routers
  • 86. The Four Principles Unity & Harmony Balance Proportion Emphasis
  • 87. The HORROR! aka What might go wrong...
  • 88. What might go wrong... Inconsistency Disproportionality
  • 89. Imbalance... Callback signatures on $.map, $.each & $(el).map
  • 90. Imbalance... Callback signatures on $.map, $.each & $(el).map
  • 91. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; Callback signatures on $.map, $.each & $(el).map
  • 92. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); Callback signatures on $.map, $.each & $(el).map
  • 93. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   Callback signatures on $.map, $.each & $(el).map
  • 94. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   Callback signatures on $.map, $.each & $(el).map
  • 95. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   var  uppers  =  $.map(letters,  function(val,  index)  {    return  (val.toUpperCase()); Callback signatures on $.map, $.each & $(el).map
  • 96. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   var  uppers  =  $.map(letters,  function(val,  index)  {    return  (val.toUpperCase()); }); Callback signatures on $.map, $.each & $(el).map
  • 97. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   var  uppers  =  $.map(letters,  function(val,  index)  {    return  (val.toUpperCase()); }); Callback signatures on $.map, $.each & $(el).map
  • 98. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   var  uppers  =  $.map(letters,  function(val,  index)  {    return  (val.toUpperCase()); }); $(‘li’).map(function(index,  val)  {  //WAT  }); Callback signatures on $.map, $.each & $(el).map
  • 99. Imbalance... var  letters  =  [“a”,  “b”,  “c”,  “d”,  “e”]; $.each(letters,  function(index,  val)  {    console.log(index  +  “:  “  +  val.toUpperCase()); });   var  uppers  =  $.map(letters,  function(val,  index)  {    return  (val.toUpperCase()); }); $(‘li’).map(function(index,  val)  {  //WAT  }); Callback signatures on $.map, $.each & $(el).map Not only do $.map and $.each diverge, but $.map and $(el).map order the callback params differently, depending on how the method is called.
  • 100. Proportion: Too Large or Too Small...
  • 101. Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg
  • 102. Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg “Van der Poel designed a computer with only one operation code...”
  • 103. Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg “... Every instruction carried out the same operation. He demonstrated the sufficiency of his operation—his machine could do anything any other computer could do...”
  • 104. Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg “...And yet it was very difficult to program....”
  • 105. Image of Fred Brooks from: http://www-set.win.tue.nl/UnsungHeroes/files/PTERA-Kosten-Poel.jpg “...the delight that came from using it was similar to... working out a crossword puzzle— a construct of intentional complexity and no intended utility.” - Fred Brooks
  • 107. AwesomeLib.do(prams); We can all agree that this is bad
  • 110. Overloads on the jQuery() method...
  • 111. jQuery(  selector  [,  context]  )  //  Select Overloads on the jQuery() method...
  • 112. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap Overloads on the jQuery() method...
  • 113. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap Overloads on the jQuery() method...
  • 114. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object Overloads on the jQuery() method...
  • 115. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap Overloads on the jQuery() method...
  • 116. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap jQuery(    jQuery  object  )  //  Clone Overloads on the jQuery() method...
  • 117. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap jQuery(    jQuery  object  )  //  Clone jQuery(  html  [,  ownerDocument  ]  )  //  Create  DOM  Elements Overloads on the jQuery() method...
  • 118. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap jQuery(    jQuery  object  )  //  Clone jQuery(  html  [,  ownerDocument  ]  )  //  Create  DOM  Elements jQuery  (  html,  props  )  //  Create  DOM  Elements Overloads on the jQuery() method...
  • 119. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap jQuery(    jQuery  object  )  //  Clone jQuery(  html  [,  ownerDocument  ]  )  //  Create  DOM  Elements jQuery  (  html,  props  )  //  Create  DOM  Elements jQuery  (  callback  )  //  Bind  DOM  loaded  function   Overloads on the jQuery() method...
  • 120. jQuery(  selector  [,  context]  )  //  Select jQuery(  element  )  //  Wrap jQuery(  object  )  //  Wrap jQuery()  //  Empty  $  Object jQuery(  elementArray  )  //  Wrap jQuery(    jQuery  object  )  //  Clone jQuery(  html  [,  ownerDocument  ]  )  //  Create  DOM  Elements jQuery  (  html,  props  )  //  Create  DOM  Elements jQuery  (  callback  )  //  Bind  DOM  loaded  function   Overloads on the jQuery() method... 11 ways to call jQuery, with 6 different contexts!
  • 121. Now, for a question...
  • 122. jQuery: Good API Design or Bad API Design? Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
  • 123. jQuery: Good API Design or Bad API Design? Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg A baseline example of “Good...”
  • 124. jQuery: Good API Design or Bad API Design? Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg A baseline example of “Good...”
  • 125.
  • 126. YES
  • 127. Here’s the point... Image from: http://laughingsquid.com/wp-content/uploads/Kevin-Bacon.jpg
  • 128. Building and evolving a useful API is hard... Image from: http://www.ibiblio.org/xml/slides/xmlone/london2002/schemas/83.html
  • 129. ...you won’t always get it right. Image from: gorestruly.com2011/09/30/rotting-americana-the-winchester-mystery-house/
  • 130. But hey, jQuery’s not perfect...
  • 131. ... so you don’t have to be either.