The Artima Developer Community
Sponsored Link

Java Community News
John Resig on JavaScript API Design

2 replies on 1 page. Most recent reply: Sep 8, 2007 3:05 PM by Peteris Krumins

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

John Resig on JavaScript API Design Posted: Sep 7, 2007 12:21 PM
Reply to this message Reply
Summary
Mozilla developer and JQuery author John Resig shares his experiences with JavaScript library design in a recent Google TechTalk video. Resig's talk highlights JavaScript best practices, including uses of JavaScript's functional features.
Advertisement

John Resig, author of the JQuery and Fuel JavaScript libraries as well as a developer at Mozilla.org, gave a recent Google TechTalk about JavaScript API design, Best Practices in Javascript Library Design. Resig not only shared JavaScript best practices, but highlighted his evolution as a JavaScript developer, including his appreciation of JavaScript's functional programming features:

I consider functional programming to be an absolutely imperative concept. Understanding closures not only makes you a better programmer, it especially makes you a better JavaScript programmer... Having an anonymous function wrapped and executed is one of the most powerful concepts in JavaScript.

Resig also talks about his experience with JQuery's API design:

  • The most important things when writing a JavaScript API.. is that your code should be orthogonal... Whenever you perform an action on an object, it should always be performed everywhere. I like to use the analogy of CRUD. In CRUD, you can add, remove, modify, delete. I like to use that when designing a new API. In [the] Fuel [JavaScript library], every single object has the same methods and properties. To get all bookmarks, you do bookmarks.all. The get all preferences, that's perferences.all. To add new preferences, you do preferences.add, or bookmarks.add. It's the same thing for every single API, using the same method names and the same conventions. So if you know how to do preferences, for example, and you want to do bookmarks, there is no learning curve.
  • Fear adding methods... Every single method you add to the API, you will have to support it.
  • Embrace removing code... Whenever possible remove code that could be handled elsewhere. Reducing the size of your API makes it easier to learn, you decrease your file size, which is especially important in JavaScript... In JQuery 1.1, we were able to reduce the file size by 47% just by removing methods and stuff that didn't need to be there.
  • Provide an upgrade path... You can't just willy-nilly remove stuff... With JQuery, if we change the API, we provide a plug-in that gave the 1.0 users an API that felt like 1.0. Another way to do it is to give 1.0 users an API that feels like the 1.1 API. Personally, I think pointing backwards is easier... It's pretty important that you cleanly identify versions so users know at which point they're upgrading to and from.
  • Reduce to a common root... Reduce your API to its most common root. When you do that, you can have a core function that you can build on top of.

Resig also talks about the importance of consistence at many levels of code, such as in naming, argument position, and in callback context.

What is your most appreciated JavaScript language feature?


Peteris Krumins

Posts: 2
Nickname: pkrumins
Registered: Sep, 2007

Re: John Resig on JavaScript API Design Posted: Sep 8, 2007 3:04 PM
Reply to this message Reply
This lecture was awesome!

I wrote out key points from the video lecture and added timestamp when they appeared.

For example:
(05:39) Similar objects should have the same method and property names so there was minimal learning curve.

They are on my blog:
<a href="http://www.catonmat.net/blog/video-lecture-best-practices-javascript-libr ary-design/">Video Lecture on Best Practices in JavaScript Library Design</a>

Peteris Krumins

Posts: 2
Nickname: pkrumins
Registered: Sep, 2007

Re: John Resig on JavaScript API Design Posted: Sep 8, 2007 3:05 PM
Reply to this message Reply
This lecture was awesome!

I wrote out key points from the video lecture and added timestamp when they appeared.

For example:
(05:39) Similar objects should have the same method and property names so there was minimal learning curve.

I posted it on my blog:
http://www.catonmat.net/blog/video-lecture-best-practices-javascript-library-design/


Sincerely,
P.Krumins

Flat View: This topic has 2 replies on 1 page
Topic: RESTful Java Development with JSR 311 and Jersey Previous Topic   Next Topic Topic: Microsoft Releases Silverlight 1.0

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use