CoffeeScript in Action – A pleasant, thorough, language-centered how-to guide – #programming #bookreview

 

CoffeeScript in Action

Patrick Lee

(Manning - paperback)

 

CoffeeScript compiles to JavaScript, that awkward, quirky mashup which remains–because of its central role in the World Wide Web–one of the world’s most heavily utilized programming languages.

When beginners first hear this about CoffeeScript, they often think: Ah, ha! I could learn that and skip having to learn JavaScript!

Nope. Sorry.

“CoffeeScript is not about avoiding JavaScript–it is about understanding JavaScript,” Patrick Lee writes in his comprehensive and pleasant new book, CoffeeScript in Action. “Learning CoffeeScript helps people to understand JavaScript.”

Lee notes: “CoffeeScript is a simple language, and there are two simple reasons for learning it. First, it fixes some problems in JavaScript that are unpleasant to work with. Second, understanding CoffeeScript will help you learn new ways of using JavaScript and new ways of programming in general.”

So, learn JavaScript and learn CoffeeScript. And, if you are hired to work with JavaScript, be very glad you took the time and effort to also learn CoffeeScript. It will come in handy.

CoffeeScript increasingly is being used to write complete applications. (Just one example: the CoffeeScript compiler used to be written in Ruby. Now it is implemented in CoffeeScript.) Likewise, CoffeeScript can work smoothly with Node.js and Ruby on Rails.

CoffeeScript is out there, and, increasingly, it is being put to work in the workaday world.

CoffeeScript in Action definitely lives up to its title. Lee’s book takes the reader from the foundations and basic building blocks of the language all the way to thoughts on the future of CoffeeScript as ECMAScript 5 and ECMAScript 6 keep bringing changes to JavaScript.

I have read and used several smaller books on CoffeeScript, including The Little Book on CoffeeScript and Jump Start CoffeeScript. These are good, and numerous other books are available. But if you want a reasonably deep understanding of CoffeeScript as a programming language, I recommend starting with, or moving up to, CoffeeScript in Action.

Patrick Lee says that his book “doesn’t try to comprehensively detail libraries, frameworks, or other ancillary matters. Instead, it concentrates only on teaching the CoffeeScript programming language from syntax, through composition, to building, testing, and deploying applications.”

The three-part, 13-chapter, 408-page (in print format) book offers dozens of short, concise code examples that illustrate such diverse aspects as objects, functions, mixins, tests, event loops, compiling, creating animations, using CoffeeScript with domain-specific languages, and deploying applications. The book also serves up some CoffeeScript cartoons, as well as practical illustrations for key points.

How long will JavaScript be around–and, with it, the impetus to learn CoffeeScript?

Lee contends that “you should count on it being around for a long time–long enough, at least, that it will probably outlast your career as a programmer.”

Si Dunn

 

Jump Start CoffeeScript – A quick guide for experienced programmers – #programming #bookreview

Jump Start CoffeeScript
Earle Castledine
(SitePoint – paperback, Kindle)

CoffeeScript is a fun yet “serious” computer language. It is, declares the coffeescript.org website, “a little language that compiles into JavaScript. Underneath that awkward Java-esque patina, JavaScript has always had a gorgeous heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.”

And therein rubs a lie, to re-coin a very old phrase. Many beginners somehow get the notion that they can take up CoffeeScript as a cool way to avoid learning JavaScript.

It is not. Your compiled code from CoffeeScript is in JavaScript, and how, exactly, do you plan to debug it if you don’t know JavaScript? (Also, a key goal of CoffeeScript is to help you learn to write better JavaScript.)

Which brings us to Jump Start CoffeeScript by Earle Castledine. This is an entertaining yet serious programming book that promises, on its cover, to show you how to “get up to speed with CoffeeScript in a weekend.”

Repeat after me: This is not a book for computer beginners, nor anyone seeking to skate around a requirement to learn JavaScript.

Castledine’s 151-page book quickly takes you, in just one chapter, from “Hello CoffeeScript!” to beginning the process of building a computer game. And, the author promises, it’s “[n]ot just the outer husk of a boring space-based shoot ‘em up, but a complete, extensible HTML5 game with tile maps, particle effects, AI, and (of course) Ninjas.”

Despite the “weekend” tagline on the cover, the book is written in part as a story in which you have one week to develop and deliver the HTML5 game as a software product. But (spoiler alert!), you will, miraculously, finish the process one day early. (This seldom happens in real-life software development.)

If you are comfortable with JavaScript, HTML and computers, Castledine’s book can provide you with an enjoyable, challenging, and useful way to learn CoffeeScript. (You will also need to have Node.js installed, so you can use npm, Node’s package manager for modules, to download and install the coffee-script module — the hyphen is required here.)

If you are not comfortable with the aforementioned qualifications, here’s another warning. To keep the book short, almost every code example is presented as an excerpt. The full pieces of code are contained within a downloadable code archive. While using the book, you are expected to open specific files and add specific lines of code. And exactly where in the file you are supposed to add them seldom is spelled out in good detail. Basically, you are supposed to know this stuff already.

For example, in Chapter 1, you are told to “Plop a canvas element into your web page using a unique ID….”

First, you have to realize that the presented excerpt is part of a particular index.html file that will become an introductory project’s web page. And as for precisely where to plop that piece of code, you just have to know. In the very next sentence, you are told: “Now we need to grab a reference to its drawing context via CoffeeScript….” This is followed by another code excerpt, and: “If you’re compiling this code with coffee, it needs to be in a separate file, compiled, then included in the web page.” And so forth.

If you don’t know what to do without further instruction, prepare to be confused.

The author is a well-known JavaScript expert who’s very good with CoffeeScript, too. And, the goal of this SitePoint book is to quickly get you up to speed with CoffeeScript.

You will get up to speed–if you possess some programming experience, know some JavaScript and HTML, and can follow the author’s instructions without needing basic 1-2-3, a-b-c steps.

Si Dunn

The Little Book on CoffeeScript – #programming #in #coffeescript #javascript #bookreview

The Little Book on CoffeeScript
By Alex MacCaw (with Jeremy Ashkenas)
(O’Reilly, paperback, list price $8.99; Kindle edition, list price $7.99)

“CoffeeScript (http://coffeescript.org) is a little language that complies down to JavaScript,” says this book’s author. “The syntax is inspired by Ruby and Python, and implements many features from those two languages. This book is designed to help you learn CoffeeScript, understand best practices, and start building awesome client-side applications.”

In just 45 pages, MacCaw does a good job of meeting those goals. It is important, he says, to note that “while CoffeeScript’s syntax is often identical with JavaScript’s, it’s not a superset, and therefore some JavaScript keywords, such as function and var, aren’t permitted, and will throw syntax errors. If you’re writing a CoffeeScript file, it needs to be pure CoffeeScript; you can’t intermingle the two languages.”

He explains that “CoffeeScript uses a straight source-to-source compiler, the idea being that every CoffeeScript statement results in an equivalent JavaScript statement.” So, to program in CoffeeScript, you need to also know JavaScript, so you can debug runtime errors.

Along with showing CoffeeScript’s syntax differences from JavaScript, the book describes CoffeeScript’s features and compares CoffeeScript’s idioms with their JavaScript counterparts.

It also shows how to: (1)  compile CoffeeScript files in static sites, using the Cake build system; (2) structure and deploy CoffeeScript client-side application, using CommonJS modules; and (3) effectively use CoffeeScript’s “ability to fix some of JavaScript’s warts.”

 The book has six chapters, and all are illustrated with code samples:

  • 1. CoffeeScript Syntax
  • 2. CoffeeScript Classes
  • 3. CoffeeScript Idioms
  • 4. Compiling CoffeeScript
  • 5. The Good Parts - Describes what CoffeeScript can’t fix about JavaScript and, more importantly, what it can.
  • 6. The Little Conclusion - Discusses “the philosophy behind the changes that CoffeeScript makes to JavaScript”…CoffeeScript aims “to express core JavaScript concepts in as simple and minimal a syntax as we can find for them.”

Alex MacCaw is a Ruby/JavaScript developer and entrepreneur and author of JavaScript Web Applications. Jeremy Ashkenas is the developer of CoffeeScript.

If you are ready to learn CoffeeScript, this nicely focused little book can help you get up to speed quickly on best practices.

#

Si Dunn is a novelist, screenwriter, freelance book reviewer, and former software technical writer and software/hardware QA test specialist. His latest book is a detective novel, Erwin’s Law. His other published works include Jump, a novella, and a book of poetry, plus several short stories, including The 7th Mars Cavalry, all available on Kindle.

CoffeeScript: Accelerated JavaScript Development – #bookreview #programming

CoffeeScript: Accelerated JavaScript Development
By Trevor Burnham
(Pragmatic Bookshelf, $29.00, paperback)

JavaScript was thrown together in 10 days and “was never meant to be the most important programming language in the world,” says Trevor Burnham, a web developer and founder of DataBraid, a startup focused on “developing data analysis and visualization tools.”

Yet, JavaScript was “understood by all major browsers,” despite their numerous differences, and it quickly became the “lingua franca of the Web,” he says in his well-written new book.

JavaScript also became a headache for many programmers struggling to learn it well enough to provide support and develop new applications.

“JavaScript is vast…[and] offers many of the best features of functional languages while retaining the feel of an imperative language,” Burnham notes. “This subtle power is one of the reasons that JavaScript tends to confound newcomers: functions can be passed around as arguments and returned from other functions; objects can be passed around as arguments and returned from other functions; objects can have new methods added at any time; in short, functions are first-class objects.”

Unfortunately, “JavaScript doesn’t have a standard interpreter,” he adds. “Instead, hundreds of browsers and server-side frameworks run JavaScript in their own way. Debugging cross-platform inconsistencies is a huge pain.”

Enter CoffeeScript, first released on Christmas Day, 2009 as “JavaScript’s less ostentatious kid brother.”

Coding in CoffeeScript requires fewer characters and fewer lines. And “the compiler tries its best to generate JavaScript Lint-compliant output, which is a great filter for common human errors and nonstandard idioms,” Burnham writes.

Another benefit: “CoffeeScript code and JavaScript code can interact freely,” he notes.

His book, aimed at CoffeeScript newcomers, assumes you have at least a little knowledge of JavaScript. But you don’t have to be a JavaScript Ninja, he assures.

He starts at the classic “Hello, world” level of CoffeeScript, including installing the CoffeeScript compiler, deciding which text editors are best, and learning how to write and debug simple CoffeeScript code.

From there, he moves quickly into showing you how to put CoffeeScript to work and develop a simple multiplayer game.

There are several different ways to run CoffeeScript, and there are different requirements, depending on whether your machine is Mac, Windows or Linux. Burnham describes these in his text and in an appendix, and he gives links to more information.

He also shows how to use a browser-based compiler for developing his book’s example application. But he does not recommend using the browser-based compiler for production work.

His book has six chapters and four appendices:

  • Chapter 1 – Getting Started
  • Chapter 2 – Functions, Scope, and Context
  • Chapter 3 – Collections and Iteration
  • Chapter 4 – Modules and Classes
  • Chapter 5 – Web Interactivity with jQuery
  • Chapter 6 – Server-Side Apps with Node.js
  • A1 – Answers to Exercises
  • A2 - Ways of Running CoffeeScript
  • A3 – Cheat Sheet for JavaScripters
  • A4 – Bibliography

CoffeeScript: Accelerated JavaScript Development offers a focused blend of examples and exercises to help speed up basic competency with CoffeeScript. In learning how to build the multiplayer game application, you use CoffeeScript to write both the client (with jQuery) and the server (with Node.js).

Since CoffeeScript and JavaScript are intertwined, you also can gain a better understanding of JavaScript by learning to code in CoffeeScript, ” Burnham promises.

In a foreword to the book, CoffeeScript’s creator, Jeremy Ashkenas, hails Burnham’s work as “a gentle introduction to CoffeeScript led by an expert guide.”

It lives up to that good billing, with many short code examples and many short tutorials and exercises that can lead quickly to building both a working app and a working understanding of CoffeeScript.

Si Dunn