SlideShare a Scribd company logo
1 of 15
Intro to CoffeeScript
A beginner’s presentation for beginners
Don’t I have to be a JSWiz?
Not even close. (But it does help)
Developer/Designer/Unicorn
Little Experience required
Simple syntax
Better transition from other language patterns
Some cool points
- Classes
- No semicolons (YAY!)
- Commas optional
- Arrow function notation
What is CoffeeScript?
CoffeeScript is an alternate syntax that compiles into Javascript. According to
the author, it is an ‘attempt to expose the good parts of JavaScript in a
simple way.
Popularity
CoffeeScript has gained much popularity since it’s inception as a GitHub gist in
2009. It has become the ‘x’-script of choice for some projects you might
have heard of, including Dropbox and GitHub, as well as many other
projects you’ve never heard of.
Usage
The widespread usage across many web apps makes this language a ‘should
do’ for any designer or developer. Even if you don’t decide to use it, you will
most likely come across it in a future project. So, DTRT and learn a thing-or-
two.
# Assignments
num = -5
isPositive = true
# Objects
Setup = ->
num: num
add: (i) ->
num + i
# Conditionals
num = 5 if isPositive
# Arrays
arr = [1,2,3,4,5]
var num, isPositive, Setup, arr,
plusOne;
num = -5;
isPositive = true;
Setup = function() {
num: num,
add: function(i) {
return num + i
}
};
if(isPositive) {
num = 5;
}
arr = [1,2,3,4,5];
So, what does it look like?
# Assignments
num = -5
isPositive = true
# Objects
Setup = ->
num: num
add: (i) ->
num + i
# Conditionals
num = 5 if isPositive
# Arrays
arr = [1,2,3,4,5]
- # -- for Comments
and
- ###
words -- for Block Comments
###
- Semicolons not required! (W00t!!
11!)
- Commas are not required, but can
be helpful.
- Indentation/syntax depended.
(Similar in nature to Ruby or Python)
- Concise syntax.
- Parentheses and Curlies are not
required, but can be helpful.
- Fun to type!
- Easier to read!
Example examined.
Installation
CoffeeScript requires Node.js and the NPM Package Manager or Ruby, which are
installed thusly:
Node.js --
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
-- OR --
Mac OS X : brew install node
Ubuntu? : apt-get install node
Everything : http://nodejs.org/download/ for Installer ackages
NPM --
curl https://npmjs.org/install.sh | sh
Ruby --
Mac OS X : comes preinstalled
Linux : may come preinstalled
Windows : http://rubyinstaller.org/
Installation, Continued
Now we can actually install CoffeeScript! YAY!!
Global :
$ sudo npm install -g coffee-script
Project :
$ npm install coffee-script
Alternatively, through GitHub (I’ve never done this one)
$ npm install -g http://github.com/jashkenas/coffee-script/tarball/master
and then, go to the coffee-script directory and type:
$ sudo bin/cake install
Now what?
Let’s play around with some ideas.
JavaScript, as of EC5, doesn’t have defined class structures and is mostly a
functional, object-oriented language. “But,” I can hear some protest, “you
can use things like Traceur and the EC6 Module Transpiler to write
JavaScript with classes and other new constructs available in Ecmascript 6.”
Well. If you’re using those things, awesome. Even you can benefit from CS!
Classes
class Car
constructor: (@name) ->
engine: (valves) ->
console.log(@name + “ is a V-#{valves}.”
class Ford extends Car
engine: ->
super 6
class Honda extends Car
engine: ->
super 4
slowCar = new Honda “Prius”
fastCar = new Ford “Cobra”
slowCar.engine()
And? In JavaScript?
var Car, Ford, Honda, fastCar, slowCar, _ref, _ref1,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor();
child.__super__ = parent.prototype; return child; };
Car = (function() {
function Car(name) {
this.name = name;
({
engine: function(valves) {
return console.log(this.name + ' is a V#{valves}.');
}
});
}
return Car;
})();
(etc...)
[
http://coffeescript.org/#try:class%20Car%0A%20%20constructor%3A%20(%40name)%20-%3E%0A%20%20%20%20engine%3
]
So that's cool...
What other neat things can be done this
easily?
JSON:
teachers =
teacher:
name: "Patrick D."
company: "Rightleaf, LLC"
teacher:
name: "Phil P."
company: "Rightleaf, LLC"
Ranges:
days = [1..7]
Existential Operator:
login() if not user?
This and This!
Splats:
giveShips = (one, two, three, rest...) ->
addOnesToShip one, 10
addOnesToShip two, 6
addOnesToShip three, 2
for ship in rest
addOnesToShip ship, 1
ships = ['rat', 'dog', 'cat', 'bull', 'horse']
giveShips ships...
(need ... to ensure assignment)
One last
"Pretty Cool Thing"
"Pretty Cool Thing"
Modules!!!!
module.exports = (engine, options = {}) ->
options.blacklist ?= []
engine = require(engine) if typeof engine is 'string'
compile: (template, data) ->
template = engine.compile(template, data)
(data) ->
for k, v of data.params
if typeof data[k] is 'undefined' and k not in options.blacklist
data[k] = v
template(data)
(sample taken and modified from
https://github.com/mauricemach/zappa/blob/master/src/zappa.coffee for effect)
Arg(h)s!!
(The good ones)
-o Output Directory
-c Compile Directory
-w Watch this Directory
-m Map JS to CS files for Debugging
-b Remove safety wrapper (a good thing IMHO)
It'll look something like this:
v--Command v---to here v--- In all these CS files
coffee -mj -o /javascripts/allYourJase.js -cw /coffeescripts/*.coffee
^^--^--Map, Join and Output ^---Compile and Watch for saves
Arguments for 'coffee', or
Compiling like a pirate
Resources
CoffeeScript Home Page:
http://coffeescript.org
Using CoffeeScript with Node and such:
http://ristrettolo.gy (online book)
Examples:
http://en.wikipedia.org/wiki/CoffeeScript
http://amix.dk/blog/post/19612 (neet post about CoffeeScript stuff, in general)
Cool Tuts:
http://blog.teamtreehouse.com/the-absolute-beginners-guide-to-coffeescript
This guy hates it, just in case you want the other point of view.
CoffeeScript: less typing, bad readability…
http://ceronman.com/2012/09/17/coffeescript-less-typing-bad-readability/

More Related Content

What's hot

Go Mobile with Apache Cordova, Zagreb 2014
Go Mobile with Apache Cordova, Zagreb 2014Go Mobile with Apache Cordova, Zagreb 2014
Go Mobile with Apache Cordova, Zagreb 2014Christian Grobmeier
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Workhorse Computing
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmersxSawyer
 
Plumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopPlumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopStefan Baumgartner
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perldeepfountainconsulting
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End WorkflowDimitris Tsironis
 
Advanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsAdvanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsStefan Baumgartner
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)xSawyer
 
Chat bot-automation-hubot
Chat bot-automation-hubotChat bot-automation-hubot
Chat bot-automation-hubotEueung Mulyana
 
CasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingCasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingFabien POMEROL
 
Ops for everyone - John Britton
Ops for everyone - John BrittonOps for everyone - John Britton
Ops for everyone - John BrittonDevopsdays
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love RubyBen Scheirman
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsRyan Weaver
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverMongoDB
 
Testing MeteorJS using CasperJS
Testing MeteorJS using CasperJSTesting MeteorJS using CasperJS
Testing MeteorJS using CasperJSStephan Hochhaus
 

What's hot (20)

Go Mobile with Apache Cordova, Zagreb 2014
Go Mobile with Apache Cordova, Zagreb 2014Go Mobile with Apache Cordova, Zagreb 2014
Go Mobile with Apache Cordova, Zagreb 2014
 
World of Logging
World of LoggingWorld of Logging
World of Logging
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 
Perl Dancer for Python programmers
Perl Dancer for Python programmersPerl Dancer for Python programmers
Perl Dancer for Python programmers
 
A Gentle Introduction to Event Loops
A Gentle Introduction to Event LoopsA Gentle Introduction to Event Loops
A Gentle Introduction to Event Loops
 
Plumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshopPlumbin Pipelines - A Gulp.js workshop
Plumbin Pipelines - A Gulp.js workshop
 
Asynchronous programming patterns in Perl
Asynchronous programming patterns in PerlAsynchronous programming patterns in Perl
Asynchronous programming patterns in Perl
 
Automating Front-End Workflow
Automating Front-End WorkflowAutomating Front-End Workflow
Automating Front-End Workflow
 
Angular2 ecosystem
Angular2 ecosystemAngular2 ecosystem
Angular2 ecosystem
 
Lies, Damn Lies, and Benchmarks
Lies, Damn Lies, and BenchmarksLies, Damn Lies, and Benchmarks
Lies, Damn Lies, and Benchmarks
 
Advanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.jsAdvanced JavaScript build pipelines using Gulp.js
Advanced JavaScript build pipelines using Gulp.js
 
PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)PerlDancer for Perlers (FOSDEM 2011)
PerlDancer for Perlers (FOSDEM 2011)
 
Chat bot-automation-hubot
Chat bot-automation-hubotChat bot-automation-hubot
Chat bot-automation-hubot
 
CasperJs Enjoy Functional Testing
CasperJs Enjoy Functional TestingCasperJs Enjoy Functional Testing
CasperJs Enjoy Functional Testing
 
Ops for everyone - John Britton
Ops for everyone - John BrittonOps for everyone - John Britton
Ops for everyone - John Britton
 
Perl Dancer, FPW 2010
Perl Dancer, FPW 2010Perl Dancer, FPW 2010
Perl Dancer, FPW 2010
 
Reasons To Love Ruby
Reasons To Love RubyReasons To Love Ruby
Reasons To Love Ruby
 
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other ToolsCool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
Cool like a Frontend Developer: Grunt, RequireJS, Bower and other Tools
 
ECMAScript 6 and the Node Driver
ECMAScript 6 and the Node DriverECMAScript 6 and the Node Driver
ECMAScript 6 and the Node Driver
 
Testing MeteorJS using CasperJS
Testing MeteorJS using CasperJSTesting MeteorJS using CasperJS
Testing MeteorJS using CasperJS
 

Viewers also liked

Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScriptStalin Thangaraj
 
Coffee script grunt
Coffee script gruntCoffee script grunt
Coffee script gruntKien Pham
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Ruby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus IteratorsRuby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus IteratorsJohn Schmidt
 

Viewers also liked (6)

Introduction to CoffeeScript
Introduction to CoffeeScriptIntroduction to CoffeeScript
Introduction to CoffeeScript
 
Coffee script grunt
Coffee script gruntCoffee script grunt
Coffee script grunt
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Ruby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus IteratorsRuby Made Simple: Blocks Plus Iterators
Ruby Made Simple: Blocks Plus Iterators
 
Coffee Script
Coffee ScriptCoffee Script
Coffee Script
 

Similar to CoffeeScript: A beginner's presentation for beginners copy

Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018Holden Karau
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...Alexander Dean
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to railsGo Asgard
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with RubyAnis Ahmad
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDAndi Smith
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA PresentationRob Tweed
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyDavid Padbury
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsJoe Ferguson
 
Introducing to node.js
Introducing to node.jsIntroducing to node.js
Introducing to node.jsJeongHun Byeon
 
Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsJoe Ferguson
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopJachym Cepicky
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principlesPerl Careers
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!cloudbring
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsPuppet
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Holden Karau
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsTobias Oetiker
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby TeamArto Artnik
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioMauricio (Salaboy) Salatino
 

Similar to CoffeeScript: A beginner's presentation for beginners copy (20)

Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018Intro - End to end ML with Kubeflow @ SignalConf 2018
Intro - End to end ML with Kubeflow @ SignalConf 2018
 
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
From Zero to Hadoop: a tutorial for getting started writing Hadoop jobs on Am...
 
Introduction to rails
Introduction to railsIntroduction to rails
Introduction to rails
 
Developing cross platform desktop application with Ruby
Developing cross platform desktop application with RubyDeveloping cross platform desktop application with Ruby
Developing cross platform desktop application with Ruby
 
Quest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFREDQuest for the Perfect Workflow for McrFRED
Quest for the Perfect Workflow for McrFRED
 
Node.js: CAMTA Presentation
Node.js: CAMTA PresentationNode.js: CAMTA Presentation
Node.js: CAMTA Presentation
 
Automate Yo' Self
Automate Yo' SelfAutomate Yo' Self
Automate Yo' Self
 
HTML5 for the Silverlight Guy
HTML5 for the Silverlight GuyHTML5 for the Silverlight Guy
HTML5 for the Silverlight Guy
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small Teams
 
Introducing to node.js
Introducing to node.jsIntroducing to node.js
Introducing to node.js
 
Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small Teams
 
PyWPS at COST WPS Workshop
PyWPS at COST WPS WorkshopPyWPS at COST WPS Workshop
PyWPS at COST WPS Workshop
 
PSGI and Plack from first principles
PSGI and Plack from first principlesPSGI and Plack from first principles
PSGI and Plack from first principles
 
Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!Rapid Prototyping FTW!!!
Rapid Prototyping FTW!!!
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Boxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of LaptopsBoxen: How to Manage an Army of Laptops
Boxen: How to Manage an Army of Laptops
 
Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018Big Data Beyond the JVM - Strata San Jose 2018
Big Data Beyond the JVM - Strata San Jose 2018
 
LISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial HandoutsLISA Qooxdoo Tutorial Handouts
LISA Qooxdoo Tutorial Handouts
 
Toolbox of a Ruby Team
Toolbox of a Ruby TeamToolbox of a Ruby Team
Toolbox of a Ruby Team
 
Java to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.ioJava to Golang: An intro by Ryan Dawson Seldon.io
Java to Golang: An intro by Ryan Dawson Seldon.io
 

Recently uploaded

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

CoffeeScript: A beginner's presentation for beginners copy

  • 1. Intro to CoffeeScript A beginner’s presentation for beginners
  • 2. Don’t I have to be a JSWiz? Not even close. (But it does help) Developer/Designer/Unicorn Little Experience required Simple syntax Better transition from other language patterns Some cool points - Classes - No semicolons (YAY!) - Commas optional - Arrow function notation
  • 3. What is CoffeeScript? CoffeeScript is an alternate syntax that compiles into Javascript. According to the author, it is an ‘attempt to expose the good parts of JavaScript in a simple way. Popularity CoffeeScript has gained much popularity since it’s inception as a GitHub gist in 2009. It has become the ‘x’-script of choice for some projects you might have heard of, including Dropbox and GitHub, as well as many other projects you’ve never heard of. Usage The widespread usage across many web apps makes this language a ‘should do’ for any designer or developer. Even if you don’t decide to use it, you will most likely come across it in a future project. So, DTRT and learn a thing-or- two.
  • 4. # Assignments num = -5 isPositive = true # Objects Setup = -> num: num add: (i) -> num + i # Conditionals num = 5 if isPositive # Arrays arr = [1,2,3,4,5] var num, isPositive, Setup, arr, plusOne; num = -5; isPositive = true; Setup = function() { num: num, add: function(i) { return num + i } }; if(isPositive) { num = 5; } arr = [1,2,3,4,5]; So, what does it look like?
  • 5. # Assignments num = -5 isPositive = true # Objects Setup = -> num: num add: (i) -> num + i # Conditionals num = 5 if isPositive # Arrays arr = [1,2,3,4,5] - # -- for Comments and - ### words -- for Block Comments ### - Semicolons not required! (W00t!! 11!) - Commas are not required, but can be helpful. - Indentation/syntax depended. (Similar in nature to Ruby or Python) - Concise syntax. - Parentheses and Curlies are not required, but can be helpful. - Fun to type! - Easier to read! Example examined.
  • 6. Installation CoffeeScript requires Node.js and the NPM Package Manager or Ruby, which are installed thusly: Node.js -- https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager -- OR -- Mac OS X : brew install node Ubuntu? : apt-get install node Everything : http://nodejs.org/download/ for Installer ackages NPM -- curl https://npmjs.org/install.sh | sh Ruby -- Mac OS X : comes preinstalled Linux : may come preinstalled Windows : http://rubyinstaller.org/
  • 7. Installation, Continued Now we can actually install CoffeeScript! YAY!! Global : $ sudo npm install -g coffee-script Project : $ npm install coffee-script Alternatively, through GitHub (I’ve never done this one) $ npm install -g http://github.com/jashkenas/coffee-script/tarball/master and then, go to the coffee-script directory and type: $ sudo bin/cake install
  • 8. Now what? Let’s play around with some ideas. JavaScript, as of EC5, doesn’t have defined class structures and is mostly a functional, object-oriented language. “But,” I can hear some protest, “you can use things like Traceur and the EC6 Module Transpiler to write JavaScript with classes and other new constructs available in Ecmascript 6.” Well. If you’re using those things, awesome. Even you can benefit from CS!
  • 9. Classes class Car constructor: (@name) -> engine: (valves) -> console.log(@name + “ is a V-#{valves}.” class Ford extends Car engine: -> super 6 class Honda extends Car engine: -> super 4 slowCar = new Honda “Prius” fastCar = new Ford “Cobra” slowCar.engine()
  • 10. And? In JavaScript? var Car, Ford, Honda, fastCar, slowCar, _ref, _ref1, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; Car = (function() { function Car(name) { this.name = name; ({ engine: function(valves) { return console.log(this.name + ' is a V#{valves}.'); } }); } return Car; })(); (etc...) [ http://coffeescript.org/#try:class%20Car%0A%20%20constructor%3A%20(%40name)%20-%3E%0A%20%20%20%20engine%3 ]
  • 11. So that's cool... What other neat things can be done this easily?
  • 12. JSON: teachers = teacher: name: "Patrick D." company: "Rightleaf, LLC" teacher: name: "Phil P." company: "Rightleaf, LLC" Ranges: days = [1..7] Existential Operator: login() if not user? This and This! Splats: giveShips = (one, two, three, rest...) -> addOnesToShip one, 10 addOnesToShip two, 6 addOnesToShip three, 2 for ship in rest addOnesToShip ship, 1 ships = ['rat', 'dog', 'cat', 'bull', 'horse'] giveShips ships... (need ... to ensure assignment)
  • 13. One last "Pretty Cool Thing" "Pretty Cool Thing" Modules!!!! module.exports = (engine, options = {}) -> options.blacklist ?= [] engine = require(engine) if typeof engine is 'string' compile: (template, data) -> template = engine.compile(template, data) (data) -> for k, v of data.params if typeof data[k] is 'undefined' and k not in options.blacklist data[k] = v template(data) (sample taken and modified from https://github.com/mauricemach/zappa/blob/master/src/zappa.coffee for effect)
  • 14. Arg(h)s!! (The good ones) -o Output Directory -c Compile Directory -w Watch this Directory -m Map JS to CS files for Debugging -b Remove safety wrapper (a good thing IMHO) It'll look something like this: v--Command v---to here v--- In all these CS files coffee -mj -o /javascripts/allYourJase.js -cw /coffeescripts/*.coffee ^^--^--Map, Join and Output ^---Compile and Watch for saves Arguments for 'coffee', or Compiling like a pirate
  • 15. Resources CoffeeScript Home Page: http://coffeescript.org Using CoffeeScript with Node and such: http://ristrettolo.gy (online book) Examples: http://en.wikipedia.org/wiki/CoffeeScript http://amix.dk/blog/post/19612 (neet post about CoffeeScript stuff, in general) Cool Tuts: http://blog.teamtreehouse.com/the-absolute-beginners-guide-to-coffeescript This guy hates it, just in case you want the other point of view. CoffeeScript: less typing, bad readability… http://ceronman.com/2012/09/17/coffeescript-less-typing-bad-readability/