SlideShare a Scribd company logo
1 of 30
Download to read offline
CoffeeScript
                          Like JavaScript, but without the horrible.




Sunday, 27 November, 11
Burke Libbey
                          Me   @burkelibbey




Sunday, 27 November, 11
The   5   Second Pitch




Sunday, 27 November, 11
var foo = function() {
                            JavaScript     return "bar";
                                         }




                          CoffeeScript   foo = -> "bar"




Sunday, 27 November, 11
“Sold! What did I just buy?”




Sunday, 27 November, 11
“CoffeeScript is a little language
            that compiles into JavaScript”
                            – Jeremy Ashkenas, CoffeeScript author




Sunday, 27 November, 11
foo = -> "bar"




                          CoffeeScript Compiler



                           (function() {
                             var foo;
                             foo = function() {
                                  return "bar";
                             };
                           }).call(this);




Sunday, 27 November, 11
“What’s wrong with JavaScript?”


                          Browser inconsistencies

                          Terrible DOM API

                          Redundant syntax




Sunday, 27 November, 11
“What’s wrong with JavaScript?”


                             Browser inconsistencies

                             Terrible DOM API

                             Redundant syntax


               Most of the issues people have with JavaScript
                     boil down to these three points.

Sunday, 27 November, 11
“What’s wrong with JavaScript?”


                                Browser inconsistencies

                                Terrible DOM API

                                Redundant syntax


                   jQuery does a fantastic job of shielding you
                                from these two.

Sunday, 27 November, 11
“What’s wrong with JavaScript?”


                               Browser inconsistencies

                               Terrible DOM API

                               Redundant syntax



                          CoffeeScript fixes this one.


Sunday, 27 November, 11
So what’s wrong with the syntax?


                                         function(x) {
                                           return x * x;
                                         }



                          For a functional language, having to write “function”
                          and “return” everywhere is more than a little strange.


Sunday, 27 November, 11
Anonymous Function Syntax

                          JavaScript   function(x) { return x * x; }

                            Scheme     (lambda (x) (* x x))

                             Erlang    fun(X) -> X * X end.

                    CoffeeScript       (x) -> x * x

                            Haskell    x -> x * x

                            Clojure    #(* % %)

Sunday, 27 November, 11
“I’m a masochist, and I like
                   typing a lot. Give me another
                              reason.”



Sunday, 27 November, 11
Rails 3.1 includes CoffeeScript
                        by default.



Sunday, 27 November, 11
...to the chagrin of hypocrites the
                     world over.



Sunday, 27 November, 11
Sunday, 27 November, 11
Fighting Rails is usually doomed
                      to failure.



Sunday, 27 November, 11
So just suck it up and learn
                                 CoffeeScript.



Sunday, 27 November, 11
Without further ado:
                  CoffeeScript Whirlwind tour



Sunday, 27 November, 11
three = -> 3

                          square = (x) -> x * x

                              add = (x, y)
                                x + y




Sunday, 27 November, 11
Default values!
        fill = (container, liquid = "coffee") ->
          "Filling the #{container} with #{liquid}..."

                          ...and string interpolation!




Sunday, 27 November, 11
YAML-like hash literals work
                                kids =
                                  brother:
                                    name: "Max"
                                    age: 11
                                  sister:
                                    name: "Ida"
                                    age: 9




Sunday, 27 November, 11
Never type “var” again!
                             CoffeeScript does it for you.




Sunday, 27 November, 11
mood = greatlyImproved if singing




Sunday, 27 November, 11
if happy and knowsIt
                            clapsHands()
                            chaChaCha()
                          else
                            showIt()




Sunday, 27 November, 11
date = if friday then sue else jill




Sunday, 27 November, 11
options or= defaults




Sunday, 27 November, 11
I’m out of slides. Time for
                                live-coding!



Sunday, 27 November, 11
Thanks!




Sunday, 27 November, 11

More Related Content

More from Burke Libbey (7)

Nix: What even is it though?
Nix: What even is it though?Nix: What even is it though?
Nix: What even is it though?
 
Ruby Internals
Ruby InternalsRuby Internals
Ruby Internals
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Fuck Yeah Nouns
Fuck Yeah NounsFuck Yeah Nouns
Fuck Yeah Nouns
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance Tuning
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes Back
 
Ruby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other MagicRuby's Object Model: Metaprogramming and other Magic
Ruby's Object Model: Metaprogramming and other Magic
 

Recently uploaded

Recently uploaded (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
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
 
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...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
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...
 

Coffeescript

  • 1. CoffeeScript Like JavaScript, but without the horrible. Sunday, 27 November, 11
  • 2. Burke Libbey Me @burkelibbey Sunday, 27 November, 11
  • 3. The 5 Second Pitch Sunday, 27 November, 11
  • 4. var foo = function() { JavaScript return "bar"; } CoffeeScript foo = -> "bar" Sunday, 27 November, 11
  • 5. “Sold! What did I just buy?” Sunday, 27 November, 11
  • 6. “CoffeeScript is a little language that compiles into JavaScript” – Jeremy Ashkenas, CoffeeScript author Sunday, 27 November, 11
  • 7. foo = -> "bar" CoffeeScript Compiler (function() { var foo; foo = function() { return "bar"; }; }).call(this); Sunday, 27 November, 11
  • 8. “What’s wrong with JavaScript?” Browser inconsistencies Terrible DOM API Redundant syntax Sunday, 27 November, 11
  • 9. “What’s wrong with JavaScript?” Browser inconsistencies Terrible DOM API Redundant syntax Most of the issues people have with JavaScript boil down to these three points. Sunday, 27 November, 11
  • 10. “What’s wrong with JavaScript?” Browser inconsistencies Terrible DOM API Redundant syntax jQuery does a fantastic job of shielding you from these two. Sunday, 27 November, 11
  • 11. “What’s wrong with JavaScript?” Browser inconsistencies Terrible DOM API Redundant syntax CoffeeScript fixes this one. Sunday, 27 November, 11
  • 12. So what’s wrong with the syntax? function(x) { return x * x; } For a functional language, having to write “function” and “return” everywhere is more than a little strange. Sunday, 27 November, 11
  • 13. Anonymous Function Syntax JavaScript function(x) { return x * x; } Scheme (lambda (x) (* x x)) Erlang fun(X) -> X * X end. CoffeeScript (x) -> x * x Haskell x -> x * x Clojure #(* % %) Sunday, 27 November, 11
  • 14. “I’m a masochist, and I like typing a lot. Give me another reason.” Sunday, 27 November, 11
  • 15. Rails 3.1 includes CoffeeScript by default. Sunday, 27 November, 11
  • 16. ...to the chagrin of hypocrites the world over. Sunday, 27 November, 11
  • 18. Fighting Rails is usually doomed to failure. Sunday, 27 November, 11
  • 19. So just suck it up and learn CoffeeScript. Sunday, 27 November, 11
  • 20. Without further ado: CoffeeScript Whirlwind tour Sunday, 27 November, 11
  • 21. three = -> 3 square = (x) -> x * x add = (x, y) x + y Sunday, 27 November, 11
  • 22. Default values! fill = (container, liquid = "coffee") -> "Filling the #{container} with #{liquid}..." ...and string interpolation! Sunday, 27 November, 11
  • 23. YAML-like hash literals work kids = brother: name: "Max" age: 11 sister: name: "Ida" age: 9 Sunday, 27 November, 11
  • 24. Never type “var” again! CoffeeScript does it for you. Sunday, 27 November, 11
  • 25. mood = greatlyImproved if singing Sunday, 27 November, 11
  • 26. if happy and knowsIt clapsHands() chaChaCha() else showIt() Sunday, 27 November, 11
  • 27. date = if friday then sue else jill Sunday, 27 November, 11
  • 28. options or= defaults Sunday, 27 November, 11
  • 29. I’m out of slides. Time for live-coding! Sunday, 27 November, 11