SlideShare a Scribd company logo
1 of 68
CoffeeScript is For
Closers
Brandon Satrom
@BrandonSatrom
UserInExperience.com
Put the
Coffee(Script)
Down!
Coffee(Script) is
for Closers!
Or…
JavaScript, Linguistics and
Cockney Rhyming Slang
Or…
How CoffeeScript Made me a
Better JavaScript Developer
So Who Am I?
Husband and Father
Web Developer & Evangelist, Microsoft
Austin, TX
www.userinexperience.com
@BrandonSatrom
github.com/bsatrom
#html5tx
Agenda
• The JavaScript Dialectic
• What?
• Where?
• How?
• Why?
VS.
A JavaScript Dialectic
Don’t Be A JavaScriptster
I loved
JavaScript
before it was
cool
Of course, I also hated it back when
everyone else did too…
Don’t Be A CoffeeScriptster
JavaScript is
lame!
Significant
Whitespace
FTW!
Let’s hope they don’t notice that I still
debug in JavaScript…
WHAT?
What is CoffeeScript?
“It’s Just JavaScript”
Or “Unfancy JavaScript”
“A polyglot language”
A Ruby, Haskell and Perl love
child…
“A little language”
Meaning…it’s not DART
Transpiler vs. Compiler
Transpiled Languages
• CoffeeScript
• Traceur
• EcmaScript 5 Parser
• Reflect.js
Compiled Languages
• DART
• GWT
• Objective-J
• ClojureScript
• JSIL
• Script#
• Emscripten
• Haxe
More A Dialect, Less A Language
Color === Colour
function(foo) {} === (foo) ->
Subtle Linguistics
Dave has two children.
His youngest is in
Reception, and his
favourite colour is
green. His oldest is Year
4, and loves to ride the
lift outside his flat.
Dave has two children.
His youngest is in Pre-
K, and his favorite color
is green. His oldest is in
3rd Grade, and he loves
to ride the elevator
outside his apartment.
Not so subtle linguistics…
Sentence Extended
Phrase
Rhymes With
I’ve got a sore billy. Billy Goat Throat
That’s a nasty old boris you’ve got
there son.
Boris Karloff Cough
Ere, you’ve got your brass wrong! Brass Tacks Facts
‘ow about a Brittney? Brittney Spears Beers
We’re all in Barney! Barney Rubble Trouble
Think he’s been smoking a bit of
Bob
Bob Hope (you get the idea)
CoffeeScript is not a
replacement for Learning
JavaScript
CoffeeScript Axiom #1
Compiles 1:1 to JavaScript
1:1 being Concept to Concept
Conceptual Equivalence
CoffeeScript
numbers = [1..10]
printNum = (number) ->
console.log "This is
number #{number}"
printNum for num in numbers
JavaScript
var num, numbers, printNum, _i,
_len;
numbers = [1, 2, 3, 4, 5, 6, 7, 8,
9, 10];
printNum = function(number) {
return console.log("This is
number " + number);
};
for (_i = 0, _len =
numbers.length; _i < _len; _i++) {
num = numbers[_i];
printNum;
}
Conceptual Equivalence
CoffeeScript
numbers = [1..10]
printNum = (number) ->
console.log "This is
number #{number}"
printNum num for num in
numbers
JavaScript
var num, numbers, printNum, _i,
_len;
numbers = [1, 2, 3, 4, 5, 6, 7, 8,
9, 10];
printNum = function(number) {
return console.log("This is
number " + number);
};
for (_i = 0, _len =
numbers.length; _i < _len; _i++) {
num = numbers[_i];
printNum(num);
}
Conceptual Equivalence
CoffeeScript
numbers = [1..10]
printNum = (number) ->
console.log "This is
number #{number}"
printNum num for num in
numbers
JavaScript
var num, numbers, printNum, _i,
_len;
numbers = [1, 2, 3, 4, 5, 6, 7, 8,
9, 10];
printNum = function(number) {
return console.log("This is
number " + number);
};
for (_i = 0, _len =
numbers.length; _i < _len; _i++) {
num = numbers[_i];
printNum(num);
}
Conceptual Equivalence
CoffeeScript
numbers = [1..10]
printNum = (number) ->
console.log "This is
number #{number}"
printNum num for num in
numbers
JavaScript
var num, numbers, printNum, _i,
_len;
numbers = [1, 2, 3, 4, 5, 6, 7, 8,
9, 10];
printNum = function(number) {
return console.log("This is
number " + number);
};
for (_i = 0, _len =
numbers.length; _i < _len; _i++) {
num = numbers[_i];
printNum(num);
}
WHERE?
Where do I get it?
Ways to Get CoffeeScript
• node.js & npm
• Script Tags
<script type=“text/coffeescript”></script>
<script src=“coffee-script.js”></script>
• Rails 3.1
• SassAndCoffee (.NET)
• CoffeeScript Packages
$ npm install –g coffee-script
Tools for CoffeeScript
• IDE Extensions/Plugins
• Asset Pipeline Tools
• Live Debugging/Preview
See more at http://bit.ly/nx6JGo
HOW?
How can I use, learn and automate it?
REPL
$ coffee
coffee> [1..10]
$ coffee –o js/ -cw lib/
COMPILE
COFFEESCRIPT BASICS
Assignment
name = “Brandon”
married = yes
children = 2
var children, married, name;
name = "Brandon";
married = true;
children = 2;
Functions
square = (x) -> x * x
printInfo = (name, numChildren) ->
“Hi #{name}, I see you have #{numChildren}
children.”
var printInfo, square;
square = function(x) {
return x * x;
};
printInfo = function(name, numChildren) {
return "Hi " + name + ", I see you have " + numChildren + "
children";
};
Strings
num = 99
“I’ve got #{num} problems, and JavaScript ain’t
one.”
city = "Brooklyn"
"No. Sleep. 'Till. #{city}"
var city, num;
num = 99;
"I've got " + num + " problems, but JavaScript ain't
one";
city = "Brooklyn";
"No. Sleep. 'Till. " + city;
Objects
kids =
bigBrother:
name: “Benjamin”
age: 2
littleBrother:
name: “Jack”
age: 1
var kids;
kids = {
bigBrother: {
name: “Benjamin”,
age: 2
},
littleBrother: {
name: “Jack”,
age: 1
}
};
Lexical Scoping
outer = 42
findMeaning = ->
inner = 43
outer
inner = findMeaning()
var findMeaning, inner,
outer;
outer = 42;
findMeaning = function() {
var inner;
inner = 43;
return outer;
};
inner = findMeaning();
Lexical Scoping 2
notGlobal = "Hello"
global = "Goodbye"
window.global = global
(function() {
var global, notGlobal;
notGlobal = "Hello";
global = "Goodbye";
window.global = global;
}).call(this);
Everything, an Expression
grade = (student) ->
if student.excellentWork
"A+"
else if student.okayStuff
if student.triedHard then "B"
else "B-"
else
"C"
eldest = if 24 > 21 then "Liz"
else "Ike"
var eldest, grade;
grade = function(student) {
if (student.excellentWork) {
return "A+";
} else if (student.okayStuff)
{
if (student.triedHard) {
return "B";
} else {
return "B-";
}
} else {
return "C";
}
};
eldest = 24 > 21 ? "Liz" :
"Ike";
Conditionals
mood = greatlyImproved if singing
if happy and knowsIt
clapsHands()
chaChaCha()
else
showIt()
lunch = if friday then water else
redBull
options or= defaults
var lunch, mood;
if (singing) {
mood = greatlyImproved;
}
if (happy && knowsIt) {
clapsHands();
chaChaCha();
} else {
showIt();
}
lunch = friday ? water :
redBull;
Options || (options =
defaults);
Operators and Aliases
CoffeeScript JavaScript
is, == ===
isnt, != !==
not !
and &&
or ||
true, yes, on true
false, no, off false
@, this this
of in
in no equivalent
How I Use CoffeeScript
Let’s pretend for a moment that
how I use it, matters.
Coffee, Cake and Growl
1. Cake (think Make or Rake)
2. ‘watch’ Task
3. wingrr (use node-growl for *nix)
msg = 'All test pass'
sys.puts msg.green
wingrr.notify msg
invoke 'build'
invoke 'tests'
WHY?
Why should I bother using it?
PRO
More succinct code
CON
Extra compile step between you and the “real”
code
PRO
Avoid Snake Pits & Get JS Patterns for Free
hi == bye
global = "everywhere?"
switch day
when "Fri", "Sat"
if day is bingoDay
go bingo
go dancing
when "Sun" then go church
else go work
(function() {
var global;
hi === bye;
global = "everywhere?";
switch (day) {
case "Fri":
case "Sat":
if (day === bingoDay) {
go(bingo);
go(dancing);
}
break;
case "Sun":
go(church);
break;
default:
go(work);
}
})();
CON
Errors and Debugging: it’s still JavaScript in there
PRO
As fast or faster JavaScript
CON
Dare I say it? Code Generation!
OK, COFFEESCRIPT IS
OPINIONATED
Like all software is…
Shirts are for
n00bs…
WITH
APOLOGIES
TO THE
NINJAS
The Five Stages of JavaScript
1. Avoidance
2. Concession
3. Abstraction
4. Failure
5. Enlightenment
arr = new Array(4, 8, 15, 16);
arr[4] = 23;
arr[5] = 42;
for (i = 0; i < arr.length; i++)
{
enterLottoNum(arr[i]);
}
var arr = [4, 8, 15, 16, 23, 42];
for (var i = 0; i < arr.length;
i++) {
enterLottoNum(arr[i]);
}
var arr, num, _i, _len;
arr = [4, 8, 15, 16, 23, 42];
for (_i = 0, _len = arr.length;
_i < _len; _i++) {
num = arr[_i];
enterLottoNum(num);
}
CoffeeScript made me want to be
a better man
CoffeeScript can help you
become a better JavaScript
programmer
CoffeeScript Axiom #2
But there’s
nothing wrong
with JavaScript!
INFLUENCING JS.NEXT
let name = “block scoped!"
const REALLY = "srsly"
#add(a, b) { a + b }
module Mod {
export const K = “foo”
export #add(x, y) { x + y }
}
WHITHER JAVASCRIPT?
“The only thing that has happened when new
languages pop up is that JavaScript gets
better.”
– Chris Williams
JavaScript Gets Better
JavaScript
jQuery, et al.
ECMAScript 5
CoffeeScript
Harmony/JS.Next
?
"We are not just
advocating a language
on top of JS that you
use to avoid JS (GWT,
Haxe, Objective-J, etc.).
We are advocating that
you all help build a
better JS on JS, which
then becomes
standardized as
JS.next." - Brendan Eich
IT’S NOT A REPLACEMENT
FOR JAVASCRIPT
CoffeeScript Axiom #3
THE JAVASCRIPT DIALECTIC, REVISITED
What Can I/We/Everyone Learn from CoffeeScript?
THOSE AXIOMS
1) It’s not a replacement for learning JavaScript
2) It can help you become a better JavaScript programmer
3) It’s not a replacement for JavaScript
Resources - http://bit.ly/...
Slides - pLWIMf
CoffeeScript Website - nfWYwn
Annotated Source - qdAXfn
CoffeeScript Koans - o1K6bL
Smooth CoffeeScript Book - nI7GEU
Jeremy & Brendan @ JSConf 2011 -
o9KieZ
“Harmony of my Dreams” - mQkdtp
QUESTIONS?
@BrandonSatrom
brsatrom@microsoft.com
UserInExperience.com

More Related Content

Similar to Coffee scriptisforclosers nonotes

Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScriptniklal
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescriptDavid Furber
 
Coffeescript - take a sip of code
Coffeescript - take a sip of codeCoffeescript - take a sip of code
Coffeescript - take a sip of codeDimitris Tsironis
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyPatrick Devins
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersMehdi Valikhani
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptBrian Mann
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptForziatech
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScriptNone
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScriptEddie Kao
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Sam Livingston-Gray
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPMariano Iglesias
 
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)ruthmcdavitt
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasminePaulo Ragonha
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHPwebhostingguy
 

Similar to Coffee scriptisforclosers nonotes (20)

Damn Fine CoffeeScript
Damn Fine CoffeeScriptDamn Fine CoffeeScript
Damn Fine CoffeeScript
 
Real life-coffeescript
Real life-coffeescriptReal life-coffeescript
Real life-coffeescript
 
Coffeescript - take a sip of code
Coffeescript - take a sip of codeCoffeescript - take a sip of code
Coffeescript - take a sip of code
 
CoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copyCoffeeScript: A beginner's presentation for beginners copy
CoffeeScript: A beginner's presentation for beginners copy
 
test
testtest
test
 
Coffeescript slides
Coffeescript slidesCoffeescript slides
Coffeescript slides
 
CoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developersCoffeeScript, An Introduction for Nodejs developers
CoffeeScript, An Introduction for Nodejs developers
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
 
Coffee script
Coffee scriptCoffee script
Coffee script
 
Object Oriented Programming In JavaScript
Object Oriented Programming In JavaScriptObject Oriented Programming In JavaScript
Object Oriented Programming In JavaScript
 
CoffeeScript
CoffeeScriptCoffeeScript
CoffeeScript
 
Happy Programming with CoffeeScript
Happy Programming with CoffeeScriptHappy Programming with CoffeeScript
Happy Programming with CoffeeScript
 
"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues"Javascript" por Tiago Rodrigues
"Javascript" por Tiago Rodrigues
 
Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)Fluent Refactoring (Lone Star Ruby Conf 2013)
Fluent Refactoring (Lone Star Ruby Conf 2013)
 
Going crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHPGoing crazy with Node.JS and CakePHP
Going crazy with Node.JS and CakePHP
 
kRouter
kRouterkRouter
kRouter
 
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
SoTWLG Intro to Code Bootcamps 2016 (Roger Nesbitt)
 
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and JasmineSingle Page Web Applications with CoffeeScript, Backbone and Jasmine
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
 
Overview of CoffeeScript
Overview of CoffeeScriptOverview of CoffeeScript
Overview of CoffeeScript
 
Building an e:commerce site with PHP
Building an e:commerce site with PHPBuilding an e:commerce site with PHP
Building an e:commerce site with PHP
 

More from Brandon Satrom

Secrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignSecrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignBrandon Satrom
 
Coding the right thing
Coding the right thingCoding the right thing
Coding the right thingBrandon Satrom
 
Keeping architectures relevant
Keeping architectures relevantKeeping architectures relevant
Keeping architectures relevantBrandon Satrom
 
Workflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingWorkflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingBrandon Satrom
 
The Future Of Work And Workflow
The Future Of Work And WorkflowThe Future Of Work And Workflow
The Future Of Work And WorkflowBrandon Satrom
 

More from Brandon Satrom (6)

Secrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API DesignSecrets of Awesome JavaScript API Design
Secrets of Awesome JavaScript API Design
 
Coding the right thing
Coding the right thingCoding the right thing
Coding the right thing
 
Workflow systems
Workflow systemsWorkflow systems
Workflow systems
 
Keeping architectures relevant
Keeping architectures relevantKeeping architectures relevant
Keeping architectures relevant
 
Workflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful ThinkingWorkflow Systems: Myths, Truths and Wishful Thinking
Workflow Systems: Myths, Truths and Wishful Thinking
 
The Future Of Work And Workflow
The Future Of Work And WorkflowThe Future Of Work And Workflow
The Future Of Work And Workflow
 

Recently uploaded

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
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 RobisonAnna Loughnan Colquhoun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 2024Rafal Los
 
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 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
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...Neo4j
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
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
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
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
 

Recently uploaded (20)

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
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
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[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
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
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...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
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...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 

Coffee scriptisforclosers nonotes

  • 1. CoffeeScript is For Closers Brandon Satrom @BrandonSatrom UserInExperience.com
  • 4. Or… How CoffeeScript Made me a Better JavaScript Developer
  • 5. So Who Am I? Husband and Father Web Developer & Evangelist, Microsoft Austin, TX www.userinexperience.com @BrandonSatrom github.com/bsatrom
  • 7. Agenda • The JavaScript Dialectic • What? • Where? • How? • Why?
  • 8. VS.
  • 10. Don’t Be A JavaScriptster I loved JavaScript before it was cool Of course, I also hated it back when everyone else did too…
  • 11. Don’t Be A CoffeeScriptster JavaScript is lame! Significant Whitespace FTW! Let’s hope they don’t notice that I still debug in JavaScript…
  • 13. “It’s Just JavaScript” Or “Unfancy JavaScript”
  • 14. “A polyglot language” A Ruby, Haskell and Perl love child…
  • 16. Transpiler vs. Compiler Transpiled Languages • CoffeeScript • Traceur • EcmaScript 5 Parser • Reflect.js Compiled Languages • DART • GWT • Objective-J • ClojureScript • JSIL • Script# • Emscripten • Haxe
  • 17. More A Dialect, Less A Language Color === Colour function(foo) {} === (foo) ->
  • 18. Subtle Linguistics Dave has two children. His youngest is in Reception, and his favourite colour is green. His oldest is Year 4, and loves to ride the lift outside his flat. Dave has two children. His youngest is in Pre- K, and his favorite color is green. His oldest is in 3rd Grade, and he loves to ride the elevator outside his apartment.
  • 19. Not so subtle linguistics… Sentence Extended Phrase Rhymes With I’ve got a sore billy. Billy Goat Throat That’s a nasty old boris you’ve got there son. Boris Karloff Cough Ere, you’ve got your brass wrong! Brass Tacks Facts ‘ow about a Brittney? Brittney Spears Beers We’re all in Barney! Barney Rubble Trouble Think he’s been smoking a bit of Bob Bob Hope (you get the idea)
  • 20. CoffeeScript is not a replacement for Learning JavaScript CoffeeScript Axiom #1
  • 21. Compiles 1:1 to JavaScript 1:1 being Concept to Concept
  • 22. Conceptual Equivalence CoffeeScript numbers = [1..10] printNum = (number) -> console.log "This is number #{number}" printNum for num in numbers JavaScript var num, numbers, printNum, _i, _len; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; printNum = function(number) { return console.log("This is number " + number); }; for (_i = 0, _len = numbers.length; _i < _len; _i++) { num = numbers[_i]; printNum; }
  • 23. Conceptual Equivalence CoffeeScript numbers = [1..10] printNum = (number) -> console.log "This is number #{number}" printNum num for num in numbers JavaScript var num, numbers, printNum, _i, _len; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; printNum = function(number) { return console.log("This is number " + number); }; for (_i = 0, _len = numbers.length; _i < _len; _i++) { num = numbers[_i]; printNum(num); }
  • 24. Conceptual Equivalence CoffeeScript numbers = [1..10] printNum = (number) -> console.log "This is number #{number}" printNum num for num in numbers JavaScript var num, numbers, printNum, _i, _len; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; printNum = function(number) { return console.log("This is number " + number); }; for (_i = 0, _len = numbers.length; _i < _len; _i++) { num = numbers[_i]; printNum(num); }
  • 25. Conceptual Equivalence CoffeeScript numbers = [1..10] printNum = (number) -> console.log "This is number #{number}" printNum num for num in numbers JavaScript var num, numbers, printNum, _i, _len; numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; printNum = function(number) { return console.log("This is number " + number); }; for (_i = 0, _len = numbers.length; _i < _len; _i++) { num = numbers[_i]; printNum(num); }
  • 26. WHERE? Where do I get it?
  • 27. Ways to Get CoffeeScript • node.js & npm • Script Tags <script type=“text/coffeescript”></script> <script src=“coffee-script.js”></script> • Rails 3.1 • SassAndCoffee (.NET) • CoffeeScript Packages $ npm install –g coffee-script
  • 28. Tools for CoffeeScript • IDE Extensions/Plugins • Asset Pipeline Tools • Live Debugging/Preview See more at http://bit.ly/nx6JGo
  • 29. HOW? How can I use, learn and automate it?
  • 31. $ coffee –o js/ -cw lib/ COMPILE
  • 33. Assignment name = “Brandon” married = yes children = 2 var children, married, name; name = "Brandon"; married = true; children = 2;
  • 34. Functions square = (x) -> x * x printInfo = (name, numChildren) -> “Hi #{name}, I see you have #{numChildren} children.” var printInfo, square; square = function(x) { return x * x; }; printInfo = function(name, numChildren) { return "Hi " + name + ", I see you have " + numChildren + " children"; };
  • 35. Strings num = 99 “I’ve got #{num} problems, and JavaScript ain’t one.” city = "Brooklyn" "No. Sleep. 'Till. #{city}" var city, num; num = 99; "I've got " + num + " problems, but JavaScript ain't one"; city = "Brooklyn"; "No. Sleep. 'Till. " + city;
  • 36. Objects kids = bigBrother: name: “Benjamin” age: 2 littleBrother: name: “Jack” age: 1 var kids; kids = { bigBrother: { name: “Benjamin”, age: 2 }, littleBrother: { name: “Jack”, age: 1 } };
  • 37. Lexical Scoping outer = 42 findMeaning = -> inner = 43 outer inner = findMeaning() var findMeaning, inner, outer; outer = 42; findMeaning = function() { var inner; inner = 43; return outer; }; inner = findMeaning();
  • 38. Lexical Scoping 2 notGlobal = "Hello" global = "Goodbye" window.global = global (function() { var global, notGlobal; notGlobal = "Hello"; global = "Goodbye"; window.global = global; }).call(this);
  • 39. Everything, an Expression grade = (student) -> if student.excellentWork "A+" else if student.okayStuff if student.triedHard then "B" else "B-" else "C" eldest = if 24 > 21 then "Liz" else "Ike" var eldest, grade; grade = function(student) { if (student.excellentWork) { return "A+"; } else if (student.okayStuff) { if (student.triedHard) { return "B"; } else { return "B-"; } } else { return "C"; } }; eldest = 24 > 21 ? "Liz" : "Ike";
  • 40. Conditionals mood = greatlyImproved if singing if happy and knowsIt clapsHands() chaChaCha() else showIt() lunch = if friday then water else redBull options or= defaults var lunch, mood; if (singing) { mood = greatlyImproved; } if (happy && knowsIt) { clapsHands(); chaChaCha(); } else { showIt(); } lunch = friday ? water : redBull; Options || (options = defaults);
  • 41. Operators and Aliases CoffeeScript JavaScript is, == === isnt, != !== not ! and && or || true, yes, on true false, no, off false @, this this of in in no equivalent
  • 42. How I Use CoffeeScript Let’s pretend for a moment that how I use it, matters.
  • 43. Coffee, Cake and Growl 1. Cake (think Make or Rake) 2. ‘watch’ Task 3. wingrr (use node-growl for *nix) msg = 'All test pass' sys.puts msg.green wingrr.notify msg invoke 'build' invoke 'tests'
  • 44. WHY? Why should I bother using it?
  • 46. CON Extra compile step between you and the “real” code
  • 47. PRO Avoid Snake Pits & Get JS Patterns for Free hi == bye global = "everywhere?" switch day when "Fri", "Sat" if day is bingoDay go bingo go dancing when "Sun" then go church else go work (function() { var global; hi === bye; global = "everywhere?"; switch (day) { case "Fri": case "Sat": if (day === bingoDay) { go(bingo); go(dancing); } break; case "Sun": go(church); break; default: go(work); } })();
  • 48. CON Errors and Debugging: it’s still JavaScript in there
  • 49. PRO As fast or faster JavaScript
  • 50. CON Dare I say it? Code Generation!
  • 51. OK, COFFEESCRIPT IS OPINIONATED Like all software is… Shirts are for n00bs…
  • 53. The Five Stages of JavaScript 1. Avoidance 2. Concession 3. Abstraction 4. Failure 5. Enlightenment
  • 54. arr = new Array(4, 8, 15, 16); arr[4] = 23; arr[5] = 42; for (i = 0; i < arr.length; i++) { enterLottoNum(arr[i]); }
  • 55. var arr = [4, 8, 15, 16, 23, 42]; for (var i = 0; i < arr.length; i++) { enterLottoNum(arr[i]); }
  • 56. var arr, num, _i, _len; arr = [4, 8, 15, 16, 23, 42]; for (_i = 0, _len = arr.length; _i < _len; _i++) { num = arr[_i]; enterLottoNum(num); }
  • 57. CoffeeScript made me want to be a better man
  • 58. CoffeeScript can help you become a better JavaScript programmer CoffeeScript Axiom #2
  • 60.
  • 61. INFLUENCING JS.NEXT let name = “block scoped!" const REALLY = "srsly" #add(a, b) { a + b } module Mod { export const K = “foo” export #add(x, y) { x + y } }
  • 62. WHITHER JAVASCRIPT? “The only thing that has happened when new languages pop up is that JavaScript gets better.” – Chris Williams
  • 63. JavaScript Gets Better JavaScript jQuery, et al. ECMAScript 5 CoffeeScript Harmony/JS.Next ?
  • 64. "We are not just advocating a language on top of JS that you use to avoid JS (GWT, Haxe, Objective-J, etc.). We are advocating that you all help build a better JS on JS, which then becomes standardized as JS.next." - Brendan Eich IT’S NOT A REPLACEMENT FOR JAVASCRIPT CoffeeScript Axiom #3
  • 65. THE JAVASCRIPT DIALECTIC, REVISITED What Can I/We/Everyone Learn from CoffeeScript?
  • 66. THOSE AXIOMS 1) It’s not a replacement for learning JavaScript 2) It can help you become a better JavaScript programmer 3) It’s not a replacement for JavaScript
  • 67. Resources - http://bit.ly/... Slides - pLWIMf CoffeeScript Website - nfWYwn Annotated Source - qdAXfn CoffeeScript Koans - o1K6bL Smooth CoffeeScript Book - nI7GEU Jeremy & Brendan @ JSConf 2011 - o9KieZ “Harmony of my Dreams” - mQkdtp

Editor's Notes

  1. So that brings me to Axiom #2. Books and online resources are great, but I would argue that using CoffeeScript is another way to become a better JavaScript developer. I am actually spinning that it generates JS for you as a good thing. I personally learned a lot in the process. And this, for me, is only true because you still have to debug the JavaScript that CoffeeScript creates.
  2. CoffeeScript Website - http://jashkenas.github.com/coffee-script/ CoffeeScript Annotated Source - http://jashkenas.github.com/coffee-script/documentation/docs/grammar.html CoffeeScript Koans - https://github.com/sleepyfox/coffeescript-koans Smooth CoffeeScript Book - http://autotelicum.github.com/Smooth-CoffeeScript/ Jeremy and Brendan @ JSConf 2011 - http://blip.tv/jsconf/jsconf2011-jeremy-ashkenas-5258082 Bendan’s “Harmony of My Dreams” Post – http://brendaneich.com/2011/01/harmony-of-my-dreams/ Slides for this talk - https://github.com/bsatrom/Presentations/tree/master/CoffeeScript