SlideShare a Scribd company logo
Writing bullet proof Javascript

        (by using CoffeeScript)
              April 2010


             @SusanPotter
Outline

1. 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 Examples
5. CoffeeScript Tools
6. 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: login

user = 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: Math




http://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.
Resources
http://coffeescript.org
IRC: freenode #coffeescript
http://github.com/jashkenas/coffee-script/issues

Twitter:
  use #coffeescript hashtag on questions/queries
  @SusanPotter for pointers :)

More Related Content

PDF
Deploying distributed software services to the cloud without breaking a sweat
PDF
Big Data! Great! Now What? #SymfonyCon 2014
PPTX
WordPress Development Environments
PPTX
Day 8 - jRuby
KEY
Contributing to rails
PDF
JBoss, Rails and the cloud
PDF
KEY
Irb Tips and Tricks
Deploying distributed software services to the cloud without breaking a sweat
Big Data! Great! Now What? #SymfonyCon 2014
WordPress Development Environments
Day 8 - jRuby
Contributing to rails
JBoss, Rails and the cloud
Irb Tips and Tricks

What's hot (20)

KEY
Freelancing and side-projects on Rails
PDF
Modern software architectures - PHP UK Conference 2015
PPTX
Untangling fall2017 week2
KEY
Asynchronous Awesome
PDF
Python to go
PPTX
Day 1 - Intro to Ruby
PDF
Padrino - the Godfather of Sinatra
PDF
Stackato v6
PDF
High Performance Drupal
PDF
Organizing Your PHP Projects (2010 ConFoo)
PDF
Server Check.in case study - Drupal and Node.js
PDF
Working with Git
KEY
Ruby Concurrency Realities
PPT
Customizing the custom loop wordcamp 2012-jeff
PPTX
Chef + AWS + CodeIgniter
PPS
Scalable Web Architectures - Common Patterns & Approaches
KEY
Hybrid concurrency patterns
PDF
Migrate PHP E-Commerce Site to Go
PPTX
React101 v3
PPTX
Day 9 - PostgreSQL Application Architecture
Freelancing and side-projects on Rails
Modern software architectures - PHP UK Conference 2015
Untangling fall2017 week2
Asynchronous Awesome
Python to go
Day 1 - Intro to Ruby
Padrino - the Godfather of Sinatra
Stackato v6
High Performance Drupal
Organizing Your PHP Projects (2010 ConFoo)
Server Check.in case study - Drupal and Node.js
Working with Git
Ruby Concurrency Realities
Customizing the custom loop wordcamp 2012-jeff
Chef + AWS + CodeIgniter
Scalable Web Architectures - Common Patterns & Approaches
Hybrid concurrency patterns
Migrate PHP E-Commerce Site to Go
React101 v3
Day 9 - PostgreSQL Application Architecture
Ad

Viewers also liked (20)

PDF
Dynamo: Not Just For Datastores
PDF
Ricon/West 2013: Adventures with Riak Pipe
PDF
Distributed Developer Workflows using Git
PDF
Link Walking with Riak
PDF
From Zero to Application Delivery with NixOS
PDF
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
PDF
Functional Algebra: Monoids Applied
PDF
Designing for Concurrency
PPTX
Running Free with the Monads
PDF
Why Haskell
KEY
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
KEY
Scaling Teams, Processes and Architectures
PPTX
Your data structures are made of maths!
KEY
Scalable Architectures - Taming the Twitter Firehose
PDF
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
KEY
Graphs in the Database: Rdbms In The Social Networks Age
KEY
The Art of Scalability - Managing growth
KEY
NoSQL Databases: Why, what and when
PDF
Monitoring at scale - Intuitive dashboard design
KEY
Trees In The Database - Advanced data structures
Dynamo: Not Just For Datastores
Ricon/West 2013: Adventures with Riak Pipe
Distributed Developer Workflows using Git
Link Walking with Riak
From Zero to Application Delivery with NixOS
From Zero To Production (NixOS, Erlang) @ Erlang Factory SF 2016
Functional Algebra: Monoids Applied
Designing for Concurrency
Running Free with the Monads
Why Haskell
Modern Algorithms and Data Structures - 1. Bloom Filters, Merkle Trees
Scaling Teams, Processes and Architectures
Your data structures are made of maths!
Scalable Architectures - Taming the Twitter Firehose
Scalaz By Example (An IO Taster) -- PDXScala Meetup Jan 2014
Graphs in the Database: Rdbms In The Social Networks Age
The Art of Scalability - Managing growth
NoSQL Databases: Why, what and when
Monitoring at scale - Intuitive dashboard design
Trees In The Database - Advanced data structures
Ad

Similar to Writing Bullet-Proof Javascript: By Using CoffeeScript (20)

PPT
Coffee script throwdown
PDF
Why I will never write JavaScript ever again*
KEY
End to-End CoffeeScript
PDF
Smooth CoffeeScript
PDF
Front-End Engineering 101
PDF
Happy Programming with CoffeeScript
PDF
Quo vadis, JavaScript? Devday.pl keynote
PDF
DSLs in JavaScript
PDF
Coffeescript unfancy javascript
PPTX
Coffee scripts with rails
PDF
CoffeeScript: The Good Parts
ODP
DiUS Computing Lca Rails Final
PDF
Type script vs javascript come face to face in battleground
PDF
Sparklife - Life In The Trenches With Spark
PPTX
CoffeeScript the Awesome
PDF
Survive JavaScript - Strategies and Tricks
PDF
General Assembly Workshop: Advanced JavaScript
PDF
Kann JavaScript elegant sein?
PDF
Let’s learn how to use JavaScript responsibly and stay up-to-date.
PDF
Web Frameworks of the Future
Coffee script throwdown
Why I will never write JavaScript ever again*
End to-End CoffeeScript
Smooth CoffeeScript
Front-End Engineering 101
Happy Programming with CoffeeScript
Quo vadis, JavaScript? Devday.pl keynote
DSLs in JavaScript
Coffeescript unfancy javascript
Coffee scripts with rails
CoffeeScript: The Good Parts
DiUS Computing Lca Rails Final
Type script vs javascript come face to face in battleground
Sparklife - Life In The Trenches With Spark
CoffeeScript the Awesome
Survive JavaScript - Strategies and Tricks
General Assembly Workshop: Advanced JavaScript
Kann JavaScript elegant sein?
Let’s learn how to use JavaScript responsibly and stay up-to-date.
Web Frameworks of the Future

More from Susan Potter (6)

PDF
Thinking in Properties
PDF
Champaign-Urbana Javascript Meetup Talk (Jan 2020)
PDF
From Zero to Haskell: Lessons Learned
PDF
Dynamically scaling a political news and activism hub (up to 5x the traffic i...
PDF
Functional Operations (Functional Programming at Comcast Labs Connect)
PDF
Twitter4R OAuth
Thinking in Properties
Champaign-Urbana Javascript Meetup Talk (Jan 2020)
From Zero to Haskell: Lessons Learned
Dynamically scaling a political news and activism hub (up to 5x the traffic i...
Functional Operations (Functional Programming at Comcast Labs Connect)
Twitter4R OAuth

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Approach and Philosophy of On baking technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPT
Teaching material agriculture food technology
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
The Rise and Fall of 3GPP – Time for a Sabbatical?
MYSQL Presentation for SQL database connectivity
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Approach and Philosophy of On baking technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
Teaching material agriculture food technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm

Writing Bullet-Proof Javascript: By Using CoffeeScript

  • 1. Writing bullet proof Javascript (by using CoffeeScript) April 2010 @SusanPotter
  • 2. Outline 1. 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 Examples 5. CoffeeScript Tools 6. Resources
  • 3. 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!
  • 4. 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
  • 5. 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
  • 6. What is CoffeeScript? Fine-grained translation layer on top of Javascript. class User constructor: (login) -> @login: login user = new User('mbbx6spp') if signedIn() $('#top-header').html('Welcome' + user.login) else $('#top-header').html('Welcome Anonymous')
  • 7. Why use CoffeeScript? Prevents common mistakes using different syntax. More terse & expressive. More readable. Generates Javascript without any JSLint warnings.
  • 8. Why not use CoffeeScript? Adds another level of indirection. Another syntax to learn. Already know Javascript (the good parts) well.
  • 9. CoffeeScript Examples: jQuery http://gist.github.com/365144
  • 11. 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
  • 12. 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.