SlideShare une entreprise Scribd logo
1  sur  15
Télécharger pour lire hors ligne
CoffeeScript
                            Write javascript easier




Monday, January 24, 2011
Javascript

                    •      Great language

                    •      60-70% of the code I write now is javascript

                    •      Javascript is the future - especially with fast
                           browsers like Chrome

                    •      Javascript is on the ugly side - braces and
                           brackets and semicolons lead to parse errors



Monday, January 24, 2011
CoffeeScript

                    • Cleans up Javascript
                    • Ruby-esque (designed to read like english)
                           and Python-esque (no ends, tab driven)
                    • Compiles to Javascript


Monday, January 24, 2011
Assignment
                           favorite_number = 314
                           is_a_programmer = true


                               # in javascript
                               var favorite_number = 314;
                               var is_a_programmer = true;




Monday, January 24, 2011
Conditions
                           if (favorite_number == 3.14)
                             is_a_programmer = true
                           else
                             is_a_programmer = false

                           alert(is_a_programmer)


                                 # Conditions in javascript
                                 if (favorite_number == 3.14) {
                                   is_a_programmer = true;
                                 } else {
                                   is_a_programmer = false;
                                 }
                                 alert(is_a_programmer);




Monday, January 24, 2011
Functions
                           area_of_circle = (r) ->
                             3.14 * (r*r)



                               # in javascript
                               area_of_circle = function(r) {
                                  return (3.14 * (r*r));
                               };




Monday, January 24, 2011
Other Stuff


                    • jQuery, Prototype, other frameworks - yes,
                           you can mix them in.
                    • Plugins - yes, you can mix them in.


Monday, January 24, 2011
Installation



                    • 1) Install node.js
                    • 2) Install npm (node package manager)
                    • 3) Install coffeescript


Monday, January 24, 2011
Install node.js

                    •      mkdir ~/sources

                    •      cd ~/sources

                    •      wget http://nodejs.org/dist/node-v0.2.6.tar.gz

                    •      sudo tar xvzf node[press tab]

                    •      cd node[press tab]

                    •      ./configure

                    •      make

                    •      sudo make install


Monday, January 24, 2011
Install npm

                    • cd ~/sources
                    • git clone http://github.com/isaacs/npm.git
                    • cd npm
                    • make
                    • sudo make install

Monday, January 24, 2011
Install coffeescript


                    • sudo npm install coffee-script



Monday, January 24, 2011
Try it out

                    • In terminal type: coffee
                    • You will get a command line interface
                           similar to irb.You can write coffee-script
                           directly from there if you wish.




Monday, January 24, 2011
Using with Rails/Sinatra/etc

                    •      Use the barista gem - https://github.com/Sutto/
                           barista

                    •      Add it to your gemfile

                    •      rails generate barista: install

                    •      edit config/initializers/barista_config.rb as necessary

                    •      Now your coffeescripts will automatically compile
                           to javascript



Monday, January 24, 2011
Good practices
                    •      Create a app/javascripts folder

                    •      Put all your coffeescript in that folder - app/javascripts/
                           application.coffee

                    •      Set config/initializers/barista_config.rb to compile to
                           public/javascripts/compiled

                    •      Now all your generated javascript from coffeescript will
                           be in a compiled folder and you can still use normal
                           javascript when necessary under your public/javascripts
                           folder



Monday, January 24, 2011
Conclusion

                    • CoffeeScript is a more enjoyable way to
                           write javascript
                    • You will make less errors writing javascript
                           with CoffeeScript
                    • You will probably write more powerful and
                           more organized code too



Monday, January 24, 2011

Contenu connexe

Similaire à Coffeescript

Expert JavaScript Programming
Expert JavaScript ProgrammingExpert JavaScript Programming
Expert JavaScript ProgrammingYoshiki Shibukawa
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrantandygale
 
Quo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteQuo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteChristian Heilmann
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingFITC
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingRami Sayar
 
scaling compiled applications - highload 2013
scaling compiled applications - highload 2013scaling compiled applications - highload 2013
scaling compiled applications - highload 2013ice799
 
Joe Damato
Joe DamatoJoe Damato
Joe DamatoOntico
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsPablo Godel
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overviewJesse Warden
 
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?Vivek Parihar
 
Oscon 2011-mueller-weinre
Oscon 2011-mueller-weinreOscon 2011-mueller-weinre
Oscon 2011-mueller-weinrepmuellr
 
Powering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with VagrantPowering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with VagrantCoen Jacobs
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 
The JavaScript Delusion
The JavaScript DelusionThe JavaScript Delusion
The JavaScript DelusionJUGBD
 
TypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxTypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxaccordv12
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGuillaume Laforge
 
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchHoward Greenberg
 

Similaire à Coffeescript (20)

Expert JavaScript Programming
Expert JavaScript ProgrammingExpert JavaScript Programming
Expert JavaScript Programming
 
Avoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and VagrantAvoiding surprises with Chef and Vagrant
Avoiding surprises with Chef and Vagrant
 
Quo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynoteQuo vadis, JavaScript? Devday.pl keynote
Quo vadis, JavaScript? Devday.pl keynote
 
Tdd
TddTdd
Tdd
 
Here Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript DebuggingHere Be Dragons – Advanced JavaScript Debugging
Here Be Dragons – Advanced JavaScript Debugging
 
FITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript DebuggingFITC - Here Be Dragons: Advanced JavaScript Debugging
FITC - Here Be Dragons: Advanced JavaScript Debugging
 
Learning to code
Learning to codeLearning to code
Learning to code
 
scaling compiled applications - highload 2013
scaling compiled applications - highload 2013scaling compiled applications - highload 2013
scaling compiled applications - highload 2013
 
Joe Damato
Joe DamatoJoe Damato
Joe Damato
 
Rock Solid Deployment of Web Applications
Rock Solid Deployment of Web ApplicationsRock Solid Deployment of Web Applications
Rock Solid Deployment of Web Applications
 
Angular 2 overview
Angular 2 overviewAngular 2 overview
Angular 2 overview
 
How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?How fast can you onboard a new team member with VAGRANT ?
How fast can you onboard a new team member with VAGRANT ?
 
Oscon 2011-mueller-weinre
Oscon 2011-mueller-weinreOscon 2011-mueller-weinre
Oscon 2011-mueller-weinre
 
Powering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with VagrantPowering Development and Testing Environments with Vagrant
Powering Development and Testing Environments with Vagrant
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
The JavaScript Delusion
The JavaScript DelusionThe JavaScript Delusion
The JavaScript Delusion
 
TypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptxTypeScript-SPS-melb.pptx
TypeScript-SPS-melb.pptx
 
Rails tools
Rails toolsRails tools
Rails tools
 
Google App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and GaelykGoogle App Engine Java, Groovy and Gaelyk
Google App Engine Java, Groovy and Gaelyk
 
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
 

Dernier

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
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, Adobeapidays
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
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 WorkerThousandEyes
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
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 CVKhem
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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 WorkerThousandEyes
 

Dernier (20)

Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 

Coffeescript

  • 1. CoffeeScript Write javascript easier Monday, January 24, 2011
  • 2. Javascript • Great language • 60-70% of the code I write now is javascript • Javascript is the future - especially with fast browsers like Chrome • Javascript is on the ugly side - braces and brackets and semicolons lead to parse errors Monday, January 24, 2011
  • 3. CoffeeScript • Cleans up Javascript • Ruby-esque (designed to read like english) and Python-esque (no ends, tab driven) • Compiles to Javascript Monday, January 24, 2011
  • 4. Assignment favorite_number = 314 is_a_programmer = true # in javascript var favorite_number = 314; var is_a_programmer = true; Monday, January 24, 2011
  • 5. Conditions if (favorite_number == 3.14) is_a_programmer = true else is_a_programmer = false alert(is_a_programmer) # Conditions in javascript if (favorite_number == 3.14) { is_a_programmer = true; } else { is_a_programmer = false; } alert(is_a_programmer); Monday, January 24, 2011
  • 6. Functions area_of_circle = (r) -> 3.14 * (r*r) # in javascript area_of_circle = function(r) { return (3.14 * (r*r)); }; Monday, January 24, 2011
  • 7. Other Stuff • jQuery, Prototype, other frameworks - yes, you can mix them in. • Plugins - yes, you can mix them in. Monday, January 24, 2011
  • 8. Installation • 1) Install node.js • 2) Install npm (node package manager) • 3) Install coffeescript Monday, January 24, 2011
  • 9. Install node.js • mkdir ~/sources • cd ~/sources • wget http://nodejs.org/dist/node-v0.2.6.tar.gz • sudo tar xvzf node[press tab] • cd node[press tab] • ./configure • make • sudo make install Monday, January 24, 2011
  • 10. Install npm • cd ~/sources • git clone http://github.com/isaacs/npm.git • cd npm • make • sudo make install Monday, January 24, 2011
  • 11. Install coffeescript • sudo npm install coffee-script Monday, January 24, 2011
  • 12. Try it out • In terminal type: coffee • You will get a command line interface similar to irb.You can write coffee-script directly from there if you wish. Monday, January 24, 2011
  • 13. Using with Rails/Sinatra/etc • Use the barista gem - https://github.com/Sutto/ barista • Add it to your gemfile • rails generate barista: install • edit config/initializers/barista_config.rb as necessary • Now your coffeescripts will automatically compile to javascript Monday, January 24, 2011
  • 14. Good practices • Create a app/javascripts folder • Put all your coffeescript in that folder - app/javascripts/ application.coffee • Set config/initializers/barista_config.rb to compile to public/javascripts/compiled • Now all your generated javascript from coffeescript will be in a compiled folder and you can still use normal javascript when necessary under your public/javascripts folder Monday, January 24, 2011
  • 15. Conclusion • CoffeeScript is a more enjoyable way to write javascript • You will make less errors writing javascript with CoffeeScript • You will probably write more powerful and more organized code too Monday, January 24, 2011