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

Nix: What even is it though?
Nix: What even is it though?Nix: What even is it though?
Nix: What even is it though?Burke Libbey
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance TuningBurke Libbey
 
The Enterprise Strikes Back
The Enterprise Strikes BackThe Enterprise Strikes Back
The Enterprise Strikes BackBurke Libbey
 
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 MagicBurke Libbey
 

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

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

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