How to NOT Learn Coffee Script in 90 Minutes
So I am tired of looking at reading otherwise reasonable articles on angular.js or atom.io and finding myself bamboozled by this crazy ruby-esque nonsense that is coffeescript. Time to learn.
My train ride home is about 90 minutes. that should be enough. Lets go
8:19 - start (http://jashkenas.github.io/coffee-script/)
Installation
Michaels-MacBook-Pro:learn_cs michael$ npm install -g coffee-script npm http GET https://registry.npmjs.org/coffee-script npm http 200 https://registry.npmjs.org/coffee-script npm http GET https://registry.npmjs.org/mkdirp npm http 200 https://registry.npmjs.org/mkdirp /usr/local/share/npm/bin/coffee -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/coffee /usr/local/share/npm/bin/cake -> /usr/local/share/npm/lib/node_modules/coffee-script/bin/cake coffee-script@1.7.1 /usr/local/share/npm/lib/node_modules/coffee-script └── mkdirp@0.3.5
done.
console
done.. I guess I’m ready (8:27). where to start…
8:33, I have written some functions in coffeescript and javascript (using a node console) the parentheses feel more solid and familiar but the coffescript is more fluid to write and I am digging that I can invoke a function without parenthesis (cube 8…. cool)
Michaels-MacBook-Pro:learn_cs michael$ coffee coffee> square = (x) -> x * x [Function] coffee> square(3) 9 coffee> cube = (x) -> square(x) * x [Function] coffee> cube 8 512 coffee>
8:39 oops, first problem, coffee command line can’t do multiline functions (node commandline can do this, i guess because it knows about brackets n stuff…)
coffee> fill = (container, liquid = “coffee”) -> [Function] coffee> “filling the #{container} with #{liquid}” ReferenceError: container is not defined
at repl:1:22…..
Ok so i can switch to multiline (thanks stack overflow) with ctrl-v (http://stackoverflow.com/questions/10491849/i-cant-write-multiline-codes-in-coffeescript-interactive-moderepl)
but it doesn’t work!
coffee> fill = (container, liquid = “coffee”) -> “filling the #{container} with #{liquid}..” [Function] coffee> fill “cup” ‘filling the cup with coffee..’ ——> shit = (container, liquid = “coffee”) -> ……. “filling the #{container} with #{liquid}..” ReferenceError: container is not defined
its now 8:55 that was seriously annoying and I have burned 17 minutes on it. poor form. switching to an IDE for mutiline i guess.
YAML style littorals are cool…
kids =
brother:
name: “max”
age: 11
sister:
name: “ida”
age: 9
console.log(kids)
Michaels-MacBook-Pro:learn_cs michael$ coffee test.cs { brother: { name: ‘max’, age: 11 },
sister: { name: ‘ida’, age: 9 } }
But If I accidentally mess up the whitespace in the file.. my code breaks!
kids = brother: name: “max” age: 11 sister: name: “ida” age: 9
console.log(kids)
Michaels-MacBook-Pro:learn_cs michael$ coffee test.cs /Users/michael/Workspace/learn_cs/test.cs:2:9: error: unexpected newline brother:
^
even single spaces can mess up the meaning of my littoral..
brother:
name: “max”
age: 11
Michaels-MacBook-Pro:learn_cs michael$ coffee test.cs { brother: { name: ‘max’ },
age: 11,
sister: { name: ‘ida’, age: 9 } }
9:10.. having serious concerns about cs now. It seems flakey
9:20.. have never had a problem with reserved words and I don’t mind typing ‘var’
9:32.. writing some code now, ifs and thens.
9:37.. running out of time. I didn’t get splats , or comprehend comprehensions.
Overall, I don’t like it.
Javascript is straightforward, the same as Java is straightforward, no surprises. I don’t mind ruby, i get that it is beautiful and all that. I think coffeescript is trying to be ruby but doesn’t quite make it. It allso seems to try to please javascript developers but doesn’t quite do that either.
All in all it’s a bit of a hot mess IMO and I will be continuing to avoid it, along with all the other things that compile to Javascript like GWT (Yuck) and Typescript (Yuck also).
Michael