I’ve been meaning to write a series of CoffeeScript examples and tutorials for this blog, but I always get hung up on explaining how to setup a consistent and easy CoffeeScript tutorial environment. So I wrote my own.
- The CoffeeScript Daily Keep up with the very latest in CoffeeScript news via this great link aggregator.
- The Trello Tech Stack Brett Kiefer summarizes Trello’s current tech stack: CoffeeScript, Backbone, HTML5 pushState, Mustache, socket.io and websockets, node.js, HAProxy, Redis, MongoDB.
Shreyank Gupta’s notes from a CoffeeScript presentation Gupta’s notes are a nice, quick summary of a lot of CoffeeScript niceties.
- Introduction to CoffeeScript (+Useful Tutorials) A nice collection of CoffeeScript tutorials.
- Understanding CoffeeScript Comprehensions If you have a ruby background and are coming to CoffeeScript then comprehensions are probably pretty foreign looking bits of syntax. Karl Seguin takes us through the basics.
Blog Rolling with MongoDB, Node.js and Coffeescript James Carr takes us through a step-by-step tutorial to build a blog using some of our favorite technologies. James also includes BDD using mocha. Nice!
Writing jQuery plugins using CoffeeScript A quick tutorial that shows us how easy it is to write a jQuery plugin using CoffeeScript.
Interactive Smooth CoffeeScript It’s the book Smooth CoffeeScript but with all the code sections as interactive widgets! If you are learning CoffeeScript this is well worth reading/playing. Here’s the chapter on functions. See that yellow box with the function example code in it? Yeah, you can edit that and see the results live. Super cool.
Tutorials and snippets to get started with CoffeeScript Jean-Baptiste Jung has collected a bunch of handy CoffeeScript tutorials into this post. If you want to branch our your CoffeeScript then head here and pick something cool.
coffee-script-pure A CoffeeScript compiler in pure Ruby.
One More Thing
- An amazing pull request rewriting Node.js in CoffeeScript Which may, in fact, be entirely too much awesome.
No CoffeeScript news over the holidays I guess.
Separating Concerns in CoffeeScript using Aspect-Oriented Programming - How to implement aspect oriented programming in CoffeeScript to get DRY code by Reg Braithwaite.
- Parleys.com - HTML5 with Play/Scala, CoffeeScript and Jade - A presentation on using HTML5, the Play Framework, Scala, CoffeeScript, and Jade to build web applications by Matt Raible.
Implementing Minecraft in WebGL (and CoffeeScript) - An article on how to implement basic features of Minecraft using WebGL and CoffeeScript by Daniel Ribeiro. Very cool!
Coffeescript for Python programmers - Shabda Raaj takes us through some simple CoffeeScript/Python syntax examples. It’s great to see just how little changes between the two languages.
Code and Resources
CoffeeScript Cookbook - A CoffeeScript community sourced book by a bunch of CoffeeScript developers. From the basics of strings and arrays to jQuery, databases, and metaprogramming: the CoffeeScript Cookbook has plenty to offer and is a great resource.
- CoffeeScript 1.2.0 released - That link shows all the git commits from 1.1.3 to 1.2.0 (oldest first). You can also checkout the official CoffeeScript changelog.
- Creating an iOS-like Home Screen with CoffeeScript - A nice and complete tutorial detailing how to replicate an iOS “home screen” using CoffeeScript, jQuery, and the Touchable jQuery plugin.
Code and Resources
Rosetta Code CoffeeScript Examples - A great list of example CoffeeScript code for a wide range of programming topics. If you feel like contributing or just want a pointer for a small problem to practice CoffeeScript with, check out their Tasks not implemented in CoffeeScript list and code them up.
A Case Against Using CoffeeScript - Ryan Florence argues that CoffeeScript isn’t a good idea because it separates the programmed code from the executed code thus increasing the difficulties debugging and maintaining the codebase. A lot of his points depend on subjective arguments, but it and its discussion on Hacker News are well worth a read.
Should You Learn CoffeeScript? - An amazing panel discussion by a good group of programmers ranging from CoffeeScript promoters to naysayers. Seriously, both the above Ryan Florence and Oscar Godson are included as well as Jeremy Ashkenas, Brendan Eich, and Trever Burnham. If you are at all interested in CoffeeScript (and I’m betting you are) this is an amazing read.
I’ve got a backlog of CoffeeScript links to get out. This issue covers my links older than a week, Issue #1 will be following shortly with the latest in CoffeeScript news, articles, and resources.
Code and Resources
CoffeeScript, Meet Backbone.js: A Tutorial - A five part Backbone.js and CoffeeScript tutorial by Adam Spooner. It starts at “Hello, Backbone!” and builds to greater complexity. Its designed to be cloned (or forked) from Github and followed locally, not just read from the site.
The Little Book on CoffeeScript - Another completely open source CoffeeScript book by Alex MacCaw. It’s also a great introduction to the basics of the language and a good go-to reference. The “Bad Parts” section is a good overview of CoffeeScript pitfalls to watch out for.
CoffeeTags - A simple tool for generating Ctags compatible CoffeeScript tags so you can easily explore CoffeeScript projects in vim.
Let’s say you want to write a small bit of CoffeeScript to do something simple like show an ajax spinner image when the user submits a given form. The powers of jQuery and CoffeeScript combine to give us:
Not too fancy right?
Key things to notice in this example
->starts a new function
- whitespace delineates the functions
- no semicolons
View this jQuery binding example on coffeescript.org.
Update: Improved CoffeeScript example from Nihad Abbasov
Nihad Abbasov (Narkoz) shared an improved version of the CoffeeScript binding. The code structure can be chained into a clean line of CoffeeScript and
@ can replace
this. Very nice!
If you want to independently write CoffeeScript (i.e. outside of Rails or another framework that automatically supports CoffeeScript) you’ll need to install a CoffeeScript compiler.
Here are the steps to get that up and running on Mac OS X. Sorry Windows and Linux folks, I don’t have tutorials written for those platforms yet. But your steps will essentially be: 1) install Node.js, 2) use npm to install coffee-script.
Step 1: Install Homebrew
Homebrew makes installing compiled from source software super easy on the Mac. Use it.
These official Homebrew installation instructions will get you setup in no time.
Step 2: Install Node.js
This one is super easy, just run the following command after you’ve installed Homebrew.
Step 3: Install npm
Step 4: Install coffee-script
-g flag says to install the package globally. The coffee-script package installs some executable scripts so installing it globally will make running them easier.
After that last command you should now have
coffee available as a command. You can test that by running
At this point the official CoffeeScript documentation is well worth a perusal if you haven’t seen it already.
Step 5: Install the TextMate Bundle
You do use TextMate, right? Ok good. Open the terminal and run the following commands.
1 2 3 4
If you get the error
coffee: command not found when trying to compile CoffeeScript in TextMate you just need to add “/usr/local/bin” to the TextMate path. Like this:
Step 6: Fix “coffee: command not found” TextMate Bundle error
- Open TextMate
- TextMate > Preferences
- Click the “Advanced” tab
- Click “Shell Variables”
- Find the “PATH” variable and double click its value
At that point your CoffeeScript bundle should behave. No need for a restart.
Alright! You’ve got a local CoffeeScript environment to play with. Go you!
Next post we’ll actually do something with CoffeeScript, and I’ll show you a technique for quickly incorporating CoffeeScript into a development project.
Hi there and welcome to my new blog on CoffeeScript! My name is Stephen Ball. This blog will be focusing on CoffeeScript and a variety of topics such as:
CoffeeScript and jQuery
CoffeeScript and APIs (e.g. Google Maps)
I’m still getting everything setup here, so it might be a couple days before the first (actual) post. Things for dropping in!