When I started reading The Little Book on CoffeeScript I had zero experience with CoffeeScript. I was looking for a book to quickly bring me up to speed since my next project will rely heavily on CoffeeScript. At 60 pages I thought the book would give me enough information to start writing CoffeeScript code. After reading the book I can say that I made the right choice. This book has given me enough knowledge to get started writing CoffeeScript code.
The book starts off with a chapter on CoffeeScript syntax in a nice, concise manner. It covers functions, loops, arrays and CoffeeScript specific operators and aliases. There were plenty of examples with just enough text to explain what was going on in the code.
The next chapter discussed classes, specifically how to declare and use them. While discussing class properties the author pointed out a shortcut as to how to set a class property to a value that will save you typing. Lets say you have a class called Animal with a Name property that you want to set by passing a value to the class’s constructor. Here’s the ‘long hand’ code for that:
constructor: (name) ->
@name = name
Not a lot of typing but the author shows you how you can do it in fewer lines. The ‘short hand’ way is here:
constructor: (@name) –>
It doesn’t seem like much but over the long haul I appreciate the short hand method. There were a few other places in the book that the author shared shortcuts like this with the reader.
Following the classes chapter, the next type for discussion was CoffeeScript idioms. Here the author points out that using the English words for things like and instead of && and or instead of || were the preferred way to do logical ‘ands’ and ‘ors’. Most of the chapter is dedicated to showing the reader how to accomplish things like how to perform ‘each’, ‘select’, ‘map’ and other functionality in the language. The text had a nice way to show a person who is new to CoffeeScript how to do the ‘typical’ programming tasks.
The next chapter give a quick overview on how you can use CoffeeScript in conjunction with Node and node packages to create an application. Overall, I found this chapter to be a nice introduction to creating an application but there were a few problems I ran into while following along. The issues I found were that when I went to run the app I was missing five modules: underscore, async, connect, qs and mime. Thankfully the error messages were straight forward and fixing the problem was as easy as running ‘npm install <module name here>’ for each module. The last bit of the chapter walked the reader through how to deploy our application to Heroku. It was much easier than I thought it would be.
The book is summarized in a chapter written by Jeremy Ashkenas, the creator of CoffeeScript. In it he discuss the philosophy behind CoffeeScript, which the quote below sums up.
When I started this book I had zero experience with CoffeeScript and I was hoping that after reading it I would feel comfortable enough to write my own code. I would say that this book has shown me enough CoffeeScript that I feel comfortable enough to start writing code for my next project.