Using JavaScript
          in Today’s World
          Sudar Muthu
          Research Engineer
GO BIG!
          Yahoo! Labs

          http://sudarmuthu.com
          http://twitter.com/sudarmuthu
What is JavaScript?
World’s most popular
programming language



     Douglas Crockford -
     http://javascript.crockford.com/popular.html
World’s most
    misunderstood
programming language


     Douglas Crockford -
     http://javascript.crockford.com/popular.html
Who am I?
To talk about JavaScript
Fan of Douglas Crockford
 http://wp.me/p4WjA-pe
The JavaScript wedding
     invitation guy ;)
 http://wp.me/p4WjA-rK
Using JavaScript in
the browser
Options
•   YUI
•   jQuery
•   MooTools
•   Backbone.js
•   Knockout.js
•   .. and a million others
When to use YUI
• You already know what JavaScript is
• To build full-fledged websites that
  have numerous components with
  interdependent dependencies
• You need lot of build-in widgets
• Need to use design patterns
• Need to have a maintainable code
When to use jQuery
• If you are new to JavaScript
• Want something that is light
• Have a simple website with lesser
  number of components
• Need a quick solution and want
  something that is easier to learn
When to use backbone.js
• Decouple data from the UI
• Use a full fledged MVC in the client
  side as well
• Want to have multiple views/clients
  (mobile, desktop, tablets etc)
• You have a clear understanding of
  JavaScript and also the MVC
  concepts
Other special purpose libraries
• Lime.js – HTML5 based game
  framework
• Processing.js – Data visualizations
  and interactive animations
• flot – JavaScript plotting library
• Raphael – Vector graphics library
Using JavaScript in
the server
Why JavaScript on the server
• Homogenous Programming
  Experience
• Easy meta programming
• Easy reflection
• Object literals
• Interpreted Langauge
What is node.js
•   Event-driven
•   Non-blocking I/O
•   Asynchronous
•   Single-threaded
•   Light weight and efficient
Why node.js
Code like this

var result = db.query("select..");
// use result


either blocks the entire process or
implies multiple execution stacks
(threads).
Why node.js
But a line of code like this

db.query("select..", function (result){
      // use result
});


allows the program to return to the
event loop immediately. No more
unnecessary threads.
Demo
Demo of callback
// execute the callback after 2 seconds
setTimeout(function () {
    console.log("World!");
}, 2000);

// print in console
console.log("Hello");



https://github.com/sudar/jsfoo/blob/master/callback.js
Demo of a server in node.js
var http = require('http'); // require the http module

// create a server
http.createServer(function (req, res) {
    // call this function when a request is received

   res.writeHead(200, {
       'Content-Type': 'text/plain'
   });

    // send this as part of the response
    res.end('Hello Worldn');
}).listen(1337, "127.0.0.1"); // listen on port 1337

// debug information
console.log('Server running at http://127.0.0.1:1337/');


       https://github.com/sudar/jsfoo/blob/master/http-server.js
When to use node.js
• Writing highly concurrent server
  applications
• Sharing application logic between
  server and client
• Peer-to-peer web applications using
  websockets
• And node.js is available in Azure
Other options to consider
•   Rhino
•   Spidermonkey
•   Narwhal
•   Nitro
Using JavaScript in
mobile applications
PhoneGap
HTML5 app platform that allows you to
write native mobile applications using
web technologies like HTML and
JavaScript


Yes it works in Windows Phone 7 as
well
When to use it?
If you need to have one code base and
develop mobile applications for

•   Android
•   iOS
•   Blackberry
•   Window Phone
•   etc
Using JavaScript in
desktop applications
Some options to consider
•   Windows metro apps
•   Yahoo Konfabulator
•   Cappuccino
•   Titanium
•   Couch DB
Other exoctic use cases
• Control USB hid devices – node-hid
• Control Serial devices – node-
  serialport
• Control Arduino – noduino
• Control Powerpoint presentations
Well, it’s all fine,
  but I don’t like
JavaScript Syntax
Then use




CoffeeScript
Demo
Questions
      Sudar Muthu
      http://sudarmuthu.com
      http://twitter.com/sudarmuthu

Using Javascript in today's world

  • 1.
    Using JavaScript in Today’s World Sudar Muthu Research Engineer GO BIG! Yahoo! Labs http://sudarmuthu.com http://twitter.com/sudarmuthu
  • 2.
  • 3.
    World’s most popular programminglanguage Douglas Crockford - http://javascript.crockford.com/popular.html
  • 4.
    World’s most misunderstood programming language Douglas Crockford - http://javascript.crockford.com/popular.html
  • 5.
    Who am I? Totalk about JavaScript
  • 6.
    Fan of DouglasCrockford http://wp.me/p4WjA-pe
  • 7.
    The JavaScript wedding invitation guy ;) http://wp.me/p4WjA-rK
  • 8.
  • 9.
    Options • YUI • jQuery • MooTools • Backbone.js • Knockout.js • .. and a million others
  • 10.
    When to useYUI • You already know what JavaScript is • To build full-fledged websites that have numerous components with interdependent dependencies • You need lot of build-in widgets • Need to use design patterns • Need to have a maintainable code
  • 11.
    When to usejQuery • If you are new to JavaScript • Want something that is light • Have a simple website with lesser number of components • Need a quick solution and want something that is easier to learn
  • 12.
    When to usebackbone.js • Decouple data from the UI • Use a full fledged MVC in the client side as well • Want to have multiple views/clients (mobile, desktop, tablets etc) • You have a clear understanding of JavaScript and also the MVC concepts
  • 13.
    Other special purposelibraries • Lime.js – HTML5 based game framework • Processing.js – Data visualizations and interactive animations • flot – JavaScript plotting library • Raphael – Vector graphics library
  • 14.
  • 15.
    Why JavaScript onthe server • Homogenous Programming Experience • Easy meta programming • Easy reflection • Object literals • Interpreted Langauge
  • 16.
    What is node.js • Event-driven • Non-blocking I/O • Asynchronous • Single-threaded • Light weight and efficient
  • 17.
    Why node.js Code likethis var result = db.query("select.."); // use result either blocks the entire process or implies multiple execution stacks (threads).
  • 18.
    Why node.js But aline of code like this db.query("select..", function (result){ // use result }); allows the program to return to the event loop immediately. No more unnecessary threads.
  • 19.
  • 20.
    Demo of callback //execute the callback after 2 seconds setTimeout(function () { console.log("World!"); }, 2000); // print in console console.log("Hello"); https://github.com/sudar/jsfoo/blob/master/callback.js
  • 21.
    Demo of aserver in node.js var http = require('http'); // require the http module // create a server http.createServer(function (req, res) { // call this function when a request is received res.writeHead(200, { 'Content-Type': 'text/plain' }); // send this as part of the response res.end('Hello Worldn'); }).listen(1337, "127.0.0.1"); // listen on port 1337 // debug information console.log('Server running at http://127.0.0.1:1337/'); https://github.com/sudar/jsfoo/blob/master/http-server.js
  • 22.
    When to usenode.js • Writing highly concurrent server applications • Sharing application logic between server and client • Peer-to-peer web applications using websockets • And node.js is available in Azure
  • 23.
    Other options toconsider • Rhino • Spidermonkey • Narwhal • Nitro
  • 24.
  • 25.
    PhoneGap HTML5 app platformthat allows you to write native mobile applications using web technologies like HTML and JavaScript Yes it works in Windows Phone 7 as well
  • 26.
    When to useit? If you need to have one code base and develop mobile applications for • Android • iOS • Blackberry • Window Phone • etc
  • 27.
  • 28.
    Some options toconsider • Windows metro apps • Yahoo Konfabulator • Cappuccino • Titanium • Couch DB
  • 29.
    Other exoctic usecases • Control USB hid devices – node-hid • Control Serial devices – node- serialport • Control Arduino – noduino • Control Powerpoint presentations
  • 30.
    Well, it’s allfine, but I don’t like JavaScript Syntax
  • 31.
  • 32.
  • 33.
    Questions Sudar Muthu http://sudarmuthu.com http://twitter.com/sudarmuthu