43
Throw-down Node.pgh Meetup

Coffee script throwdown

Embed Size (px)

DESCRIPTION

Node.pgh Meetup 0.13

Citation preview

Page 1: Coffee script throwdown

Throw-downNode.pgh Meetup

Page 2: Coffee script throwdown

UX Designer & DeveloperNicholas McClay

@nickmcclay

Page 3: Coffee script throwdown

There are a lot of opinions about CoffeeScript

Page 4: Coffee script throwdown
Page 5: Coffee script throwdown

“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

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

here...

Page 7: Coffee script throwdown

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

.coffee .js

Compile

What is a Trans-compilingLanguage?

Page 9: Coffee script throwdown

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

Why should I care about CoffeeScript?

Page 11: Coffee script throwdown

Question: How many of you use CoffeeScript?

Page 12: Coffee script throwdown

Question: How many of you have used a

module written in CoffeeScript?

Page 13: Coffee script throwdown

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

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

Getting Started with CoffeeScript

Page 16: Coffee script throwdown

Learning CoffeeScript

http://coffeescript.codeschool.com/

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

Page 17: Coffee script throwdown

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

Basic Node Connect Server

Page 19: Coffee script throwdown

CoffeeScript Principles

1 - Clarity1 - Clarity

2 - Uniformity2 - Uniformity

3 - Ease of Translationto JavaScript

3 - Ease of Translationto JavaScript

Page 20: Coffee script throwdown

Clarity

Page 21: Coffee script throwdown

Significant White Space

1/2 to 1/3 compared to pure JavaScript

Page 22: Coffee script throwdown

Keywords

Page 23: Coffee script throwdown

Default Arguments

Page 24: Coffee script throwdown

((Parentheticals) Optional)

Page 25: Coffee script throwdown

Uniformity

Everything is an expression!

Page 26: Coffee script throwdown

Language Enhancements

Array Comprehension, Classes, and much more...

Page 27: Coffee script throwdown

Fix some JavaScript pitfalls

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

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

Page 28: Coffee script throwdown

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

Learning Pains

Page 30: Coffee script throwdown

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

Mind the gap...

Page 32: Coffee script throwdown

Mind the gap...

Page 33: Coffee script throwdown

Punctuation Counts...

Page 34: Coffee script throwdown

Punctuation Counts...

OR

Page 35: Coffee script throwdown

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

CoffeeScript Debugging Strategies

Page 37: Coffee script throwdown

Mental Map Debugging

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

Page 38: Coffee script throwdown

Source Map Debugging

.js .map .coffee

Page 39: Coffee script throwdown

WebStorm + CoffeeScript

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

Page 40: Coffee script throwdown

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

Even products that advertise CoffeeScript support can have

issues...

Page 42: Coffee script throwdown

Add “await” and “defer” keywords for async

Page 43: Coffee script throwdown

Thanks!

@nickmcclay