Coffee script throwdown

Preview:

DESCRIPTION

Node.pgh Meetup 0.13

Citation preview

Throw-downNode.pgh Meetup

UX Designer & DeveloperNicholas McClay

@nickmcclay

There are a lot of opinions about CoffeeScript

“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!”

Let’s take a deep breath and try and have an open mind

here...

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

?

.coffee .js

Compile

What is a Trans-compilingLanguage?

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!”

Why should I care about CoffeeScript?

Question: How many of you use CoffeeScript?

Question: How many of you have used a

module written in CoffeeScript?

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

Currently ranked 4th as the most depended upon

module in NPM

More than Express! (just barely)

And Yet...Larger Node Community

Yes

Getting Started with CoffeeScript

Learning CoffeeScript

http://coffeescript.codeschool.com/

http://arcturo.github.com/library/coffeescript/

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

Basic Node Connect Server

CoffeeScript Principles

1 - Clarity1 - Clarity

2 - Uniformity2 - Uniformity

3 - Ease of Translationto JavaScript

3 - Ease of Translationto JavaScript

Clarity

Significant White Space

1/2 to 1/3 compared to pure JavaScript

Keywords

Default Arguments

((Parentheticals) Optional)

Uniformity

Everything is an expression!

Language Enhancements

Array Comprehension, Classes, and much more...

Fix some JavaScript pitfalls

this, null and undefined, prototype wackiness, goodbye default global!

http://bonsaiden.github.com/JavaScript-Garden/

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

Learning Pains

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

Mind the gap...

Mind the gap...

Punctuation Counts...

Punctuation Counts...

OR

CoffeeScript Pain Points?

Requires a compilation step (use file watcher or --watch)

Community is a subset of larger JavaScript community

Debugging...

CoffeeScript Debugging Strategies

Mental Map Debugging

“You wanted to write it in CoffeeScript, you figure it out.”

Source Map Debugging

.js .map .coffee

WebStorm + CoffeeScript

http://www.youtube.com/watch?v=Sl1Uk3zT5Fg

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...

Even products that advertise CoffeeScript support can have

issues...

Add “await” and “defer” keywords for async

Thanks!

@nickmcclay