• Save
Writing Bullet-Proof Javascript: By Using CoffeeScript
Upcoming SlideShare
Loading in...5

Writing Bullet-Proof Javascript: By Using CoffeeScript



CoffeeScript talk slides given by Susan Potter in April 2010 at the University of Illinois Research Park.

CoffeeScript talk slides given by Susan Potter in April 2010 at the University of Illinois Research Park.



Total Views
Views on SlideShare
Embed Views



1 Embed 1

http://www.linkedin.com 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Writing Bullet-Proof Javascript: By Using CoffeeScript Writing Bullet-Proof Javascript: By Using CoffeeScript Presentation Transcript

  • Writing bullet proof Javascript (by using CoffeeScript) April 2010 @SusanPotter
  • Outline1. Javascript lifecycle: copy-n-paste (mid/late-90s) coarse-grained translation layers (mid-00s) (unobtrusive) pure Javascript (late-00s)2. What is CoffeeScript?3. Why use CoffeeScript?4. CoffeeScript Examples5. CoffeeScript Tools6. Resources
  • Copy-n-paste (mid/late-90s) Used mostly for: preloading images image hover-overs alerts/confirms Lots of dreadful Dreamweaver snippets Wild west era of Javascript Nobody really understood Javascript Bad Javascript snippets spread like wild fire!
  • Coarse-grained translation layers (mid-00s) Ruby on Rails popularized this with RJS & JS helpers. "AJAX-friendly" frameworks started appearing in other languages: Python, Groovy, Erlang, PHP, etc. RJS-style good for specific coarse-grained functionality. RJS-style bad when you need more flexibility & control. RJS-style promotes bad code smells: long templates, methods inline Javascript (inflexible & non-reusable) hard to debug and troubleshoot
  • Pure Javascript (late-00s) Everyone wanted to be a Javascript ninja & unobtrusive Javascript (UJS) became cool with rise of libraries. Pro: most control and flexibility Pro: libraries made UJS and better JS style easier and more accessible. Con: common Javascript pitfalls: devs still consider it secondary or tertiary language easy to pollute global space accidentally large "falsey" values can cause problems unintuitive prototypal object-oriented many others too numerous to list
  • What is CoffeeScript? Fine-grained translation layer on top of Javascript.class User constructor: (login) -> @login: loginuser = new User(mbbx6spp)if signedIn() $(#top-header).html(Welcome + user.login)else $(#top-header).html(Welcome Anonymous)
  • Why use CoffeeScript? Prevents common mistakes using different syntax. More terse & expressive. More readable. Generates Javascript without any JSLint warnings.
  • Why not use CoffeeScript? Adds another level of indirection. Another syntax to learn. Already know Javascript (the good parts) well.
  • CoffeeScript Examples: jQuery http://gist.github.com/365144
  • CoffeeScript Examples: Mathhttp://gist.github.com/365187
  • CoffeeScript Examples: OO http://gist.github.com/365215 CoffeeScript: lines 35 Javascript: lines 60 CoffeeScript: more readable Javascript generated: optimized and zero JS Lint warnings
  • CoffeeScript Tools bistro_car: Rails plugin http://github.com/jnicklas/bistro_car Rails applications only, lacking optimization. Rack adapter for CoffeeScript http://github.com/mattly/rack-coffee Ruby/Rack applications only. Caffeinator http://github.com/mbbx6spp/caffeinator Coming soon, not yet ready! Goals: Any framework, any Javascript optimization.
  • Resourceshttp://coffeescript.orgIRC: freenode #coffeescripthttp://github.com/jashkenas/coffee-script/issuesTwitter: use #coffeescript hashtag on questions/queries @SusanPotter for pointers :)