Saturday, December 3, 2011

Review of CoffeeScript: Accelerated JavaScript Development

It's been awhile since I've sunk my teeth into a good book review so I'm finally glad to get my appetite back and start consuming Trevor Burnham's CoffeeScript: Accelerated JavaScript Development book. I'm actually just as interested in trying out CoffeeScript itself as in having a look at what the book has to offer. Well then, let's get started.

First off, before even getting into the book, what is "CoffeeScript"? For a quick and dirty definition, I hit up Wikipedia:
CoffeeScript is a programming language that transcompiles to JavaScript. The language adds syntactic sugar inspired by Ruby, Python and Haskell to enhance JavaScript's brevity and readability, as well as adding more sophisticated features like array comprehension and pattern matching. CoffeeScript compiles predictably to JavaScript and programs can be written with less code (typically 1/3 fewer lines) with no effect on runtime performance. Since March 16, 2011, CoffeeScript has been on GitHub's list of most-watched projects.
I suppose I could say that if you don't know what CoffeeScript is, you shouldn't be reading Burnham's book, but that's probably not true. According to the "Who This Book Is For" section in the Preface:
If you're interested in learning CoffeeScript, you've come to the right place! However, because CoffeeScript is so closely linked to JavaScript, there are really two languages running through this book - and not enough pages to teach you both. Therefore, I'm going to assume that you know some JavaScript."
The author goes on to say that even if you know just a bit of JavaScript, you should be OK, but rank novices at the language might want to get to know a bit of JavaScript before tackling CoffeeScript. Also, since Ruby inspired a lot of the features in CoffeeScript, having a bit of Ruby background is a plus.

A couple of other "support" features before diving into the book and CoffeeScript. The sample code used in the book can be found on the book's official page at Pragmatic along with links to the errata, the discussion forums and of course, how to buy the book in hardcopy, ebook, or both formats.

How to get CoffeeScript.

I chose to use Ubuntu for my "testing platform" but was running Ubuntu's last LTS version, which doesn't support installing CoffeeScript, even in an exceptionally painful manner. Therefore, I upgraded my Ubuntu box to 11.10 (Oneiric Ocelot), opened the Ubuntu Software Center, and searched for CoffeeScript. It was discovered in no time and I installed it with no difficulty. Notice that this means I completely blew off the instructions for installing CoffeeScript as found in the first chapter, but since the book was published last August and the production version of 11.10 didn't become available until October, I figured, "what the heck". We'll see if my impatience will come back to bite me in the rear.

So now I have CoffeeScript. How am I going to use it? Oh, yeah. I have this book.

Anxious to "meet coffee", I opened a terminal window and just for giggles, typed "coffee -v" to see what version I had. So far, so good, I have version 1.1.1, the same version used in the book (the latest version as I write this blog post is 1.1.3).

There are all kinds of text editors you can use with CoffeeScript, but the author, apparently being a Mac guy, prefers textmate. Fine and dandy, but I use Ubuntu and prefer Vim. Apparently, there are textmate plugins for a wide variety of text editors including Emacs, gedit, jEdit, and of course, Vim. You can choose to go through the time and effort of adding the plug-in but you don't have to. As it says in the book, any text editor will do.

I have to say two very good things about this book. First off, the author obviously knows CoffeeScript. This is evidenced by the apparent ease at which he explains the concepts and the whirlwind tour he takes the reader through. The whirlwind tour is the second good thing since the reader gets started programming right away and dives into a practical project. If you are a beginning web developer, this book is well suited to your experience level. Unfortunately, for the beginner (and probably more advanced readers), the book has some drawbacks. I'm not sure Burnham knew exactly who to write the book for. At some points, you need to understand some JavaScript to know what's going on and at others, the author goes to some length to explain aspects of HTML and CSS (which I would presume the reader should know if they're taking on a web development programming language).

I don't mind books for beginners and in fact, I encourage them, and as an author, I can certainly understand when a publisher asks that you limit your page count to under 150 and thus limit the scope of your book, but it's as if Burnham couldn't decide how to best make use of his 138 pages. While it's good not to overwhelm novice programmers with a lot of details, beginners also tend to get confused easily if tasks and concepts are not sufficiently explored. Based on his writing style and presentation, it seems like Burnham is probably a very likable and knowledgable person, so I hate to give his book a less than stellar rating, but with CoffeeScript, JavaScript as well as jQuery, HTML, and CSS all tossed into the middle of the salad, it was hard to see the overall focus of this small text.

I do like that the book devoted itself to creating a single product (a simple game) throughout the chapters and allowed the reader to make and refine this game as a way to learn basic CoffeeScript, but in my opinion, the book is as frustrating as it is illuminating. If you're interested in learning CoffeeScript and you have at least a little programming experience, I won't say not to buy Pragmatic's CoffeeScript book, but I would recommend also spending a lot of time at coffeescript.org which, in and of itself, isn't a bad way to learn this language.

4 comments:

  1. You're welcome. Always aiming to please.

    ReplyDelete
  2. I've been keeping an eye on CoffeeScript for some time now. Interesting language. Thanks for the review, I might have to pick up this book.

    ReplyDelete
  3. I came across a couple of CoffeeScript articles at Code Project I thought I'd share. They'll make you think twice about CoffeeScript:

    Should you learn CoffeeScript?

    A Case Against CoffeeScript

    ReplyDelete
  4. CoffeeScript: Accelerated JavaScript Development is the best book for java development. In my project work this book helps me in every stage.

    ReplyDelete

Please make comments.