coffee script throwdown
DESCRIPTION
Node.pgh Meetup 0.13TRANSCRIPT
![Page 1: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/1.jpg)
Throw-downNode.pgh Meetup
![Page 2: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/2.jpg)
UX Designer & DeveloperNicholas McClay
@nickmcclay
![Page 3: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/3.jpg)
There are a lot of opinions about CoffeeScript
![Page 4: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/4.jpg)
![Page 5: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/5.jpg)
“You can take my JavaScript when you pry it from
my cold dead hands!”
“You can take my JavaScript when you pry it from
my cold dead hands!”
![Page 6: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/6.jpg)
Let’s take a deep breath and try and have an open mind
here...
![Page 7: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/7.jpg)
What is
CoffeeScript is a small language that compiles into JavaScript
Usable for client-side and server-side applications (Node.js)
Has an opinionated alternative syntax for building JavaScript applications
?
![Page 8: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/8.jpg)
.coffee .js
Compile
What is a Trans-compilingLanguage?
![Page 9: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/9.jpg)
http://altjs.org/
Objective-J
Pick your problem
“I want strict typing!”
“I work at google!”
“I want Objective-C!”
“I want functional programming!”
“I want a better JavaScript!”
![Page 10: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/10.jpg)
Why should I care about CoffeeScript?
![Page 11: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/11.jpg)
Question: How many of you use CoffeeScript?
![Page 12: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/12.jpg)
Question: How many of you have used a
module written in CoffeeScript?
![Page 13: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/13.jpg)
Isaac Schleuter (maintainer of Node.js / NPM)
TJ Holowaychuk (express, Jade, Mocha)
Mikeal Rogers (Request)
James Haliday "substack" (Browserify, dnode, Optimist)
Guillermo Rauch (Socket.IO)
Aaron Heckmann (Mongoose)
Nathan Rajich "Too Tall Nate" (node-gyp)
Marak Squires (Hook.io, pdf.js, color.js)
Felix Geisendörfer
Tim Caswell (NVM)
Node’s top contributors
http://procbits.com/2012/05/18/why-do-all-the-great-node-js-developers-hate-coffeescript
NoNoNoNoNo
NoNoNoNo
No
![Page 14: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/14.jpg)
Currently ranked 4th as the most depended upon
module in NPM
More than Express! (just barely)
And Yet...Larger Node Community
Yes
![Page 15: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/15.jpg)
Getting Started with CoffeeScript
![Page 16: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/16.jpg)
Learning CoffeeScript
http://coffeescript.codeschool.com/
http://arcturo.github.com/library/coffeescript/
![Page 17: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/17.jpg)
Give it a try!
sudo npm install -g coffee-script
coffee
coffee --compile <path to js file>
coffee --watch --compile <path to js file>
coffee --nodejs <path to node.js file>
Install
Start the CoffeeScript REPL
Compile a .coffee file into equivalent .js
Compile .coffee file when source changes
Compile and start file with Node.js
![Page 18: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/18.jpg)
Basic Node Connect Server
![Page 19: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/19.jpg)
CoffeeScript Principles
1 - Clarity1 - Clarity
2 - Uniformity2 - Uniformity
3 - Ease of Translationto JavaScript
3 - Ease of Translationto JavaScript
![Page 20: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/20.jpg)
Clarity
![Page 21: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/21.jpg)
Significant White Space
1/2 to 1/3 compared to pure JavaScript
![Page 22: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/22.jpg)
Keywords
![Page 23: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/23.jpg)
Default Arguments
![Page 24: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/24.jpg)
((Parentheticals) Optional)
![Page 25: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/25.jpg)
Uniformity
Everything is an expression!
![Page 26: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/26.jpg)
Language Enhancements
Array Comprehension, Classes, and much more...
![Page 27: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/27.jpg)
Fix some JavaScript pitfalls
this, null and undefined, prototype wackiness, goodbye default global!
http://bonsaiden.github.com/JavaScript-Garden/
![Page 28: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/28.jpg)
Ease of Translation to Javascript
The golden rule of CoffeeScript is: "It's just JavaScript"
The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings
![Page 29: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/29.jpg)
Learning Pains
![Page 30: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/30.jpg)
CoffeeScript is NOT a superset of JavaScript
CoffeeScript is compiled NOT interpreted at runtime
You must SHOULD learn JavaScript before using CoffeeScript
Compiled CoffeeScript CAN be slower than pure JavaScript, but really this usually isn’t an issue.
CoffeeScript Misunderstandings
![Page 31: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/31.jpg)
Mind the gap...
![Page 32: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/32.jpg)
Mind the gap...
![Page 33: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/33.jpg)
Punctuation Counts...
![Page 34: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/34.jpg)
Punctuation Counts...
OR
![Page 35: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/35.jpg)
CoffeeScript Pain Points?
Requires a compilation step (use file watcher or --watch)
Community is a subset of larger JavaScript community
Debugging...
![Page 36: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/36.jpg)
CoffeeScript Debugging Strategies
![Page 37: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/37.jpg)
Mental Map Debugging
“You wanted to write it in CoffeeScript, you figure it out.”
![Page 38: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/38.jpg)
Source Map Debugging
.js .map .coffee
![Page 39: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/39.jpg)
WebStorm + CoffeeScript
http://www.youtube.com/watch?v=Sl1Uk3zT5Fg
![Page 40: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/40.jpg)
Issue in WebStorm 6
http://youtrack.jetbrains.com/issue/WEB-7091
CoffeeScript gives you :
WebStorm wants :
Manually adjusting the source map reference makes it work...
![Page 41: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/41.jpg)
Even products that advertise CoffeeScript support can have
issues...
![Page 42: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/42.jpg)
Add “await” and “defer” keywords for async
![Page 43: Coffee script throwdown](https://reader038.vdocument.in/reader038/viewer/2022103114/554f464cb4c905423f8b4947/html5/thumbnails/43.jpg)
Thanks!
@nickmcclay