Ember.js in Action – An ambitious overview, with glitches – #programming #bookreview

Ember.js in Action

Joachim Haagen Skeie

(Manning – paperback)


The Ember.js JavaScript framework has “a steep learning curve,” Joachim Haagen Skeie cautions readers repeatedly in his new book.

Indeed, Ember does. I’ve watched that learning curve confuse and frustrate several experienced JavaScript and Ruby on Rails developers. And I’ve banged my own (thick) skull against the Ember.js framework several times while (1) trying to learn it from an assortment of books and websites, including emberjs.com, and (2) building a few basic apps.

Skeie’s new book is an ambitious overview of software that bills itself as “a framework for creating ambitious web applications.” And Skeie ambitiously does not start out with a lame “Hello, World!” example. Right in Chapter 1, you dive into building a real-world application for creating, editing, posting and deleting notes. ” The source code for the Notes application weighs in at about 200 lines of code and 130 lines of CSS, including the templates and JavaScript source code,” Skeie points out. “You should be able to develop and run this application on any Windows-, Mac-, or Linux-based platform using only a text editor.”

I got  the Notes app to (mostly) run on a Windows machine and a Linux machine. But I can’t get it to save the contents of notes, even though I downloaded the book’s code samples, and my code seems to match what the author highlights in his book. (Still trying to sort out the problem. Perhaps something is wrong in my setups?)

I hate writing mixed reviews. It takes enormous effort and thought to create and finish a book. And I have been looking and hoping for a solid how-to text on Ember. For me, however, this book has two key downsides. First, the code examples are written for Ember.js 1.0.0, and as this review is being written, Ember.js 1.5.1 is the latest release (with 1.6 in beta). Second, the book’s opening chapter is very difficult for beginners to follow.

Some other reviewers also have noticed problems with the book’s example code –which, for me, forms the heart of a good how-to book. And they have taken issue with how the code is presented in the text.

Still, there is much to like here, especially if you are experienced in JavaScript and in model-view-controller (MVC) frameworks and have been curious about Ember.js.

I am fairly new to Ember, so some of the chapters most helpful to me have included using Handlebars js, testing Ember.js applications and creating custom Ember.js components–areas not given much notice in the other Ember books I have read.

If you are new to JavaScript and to frameworks, do not attempt to dive into Ember.js in Action as your first Ember exposure. Start with the Ember.js website and some simpler books first. Then, consider this book.

Hopefully, in the next edition, the all-important opening chapter will be reworked, and the code examples will be presented in a clearer and more complete fashion.

Si Dunn


Functional JavaScript – Applying functional techniques and Underscore.js – #programming #bookreview

Functional JavaScript
Introducing Functional Programming with Underscore.js
Michael Fogus
(O’Reilly – paperback, Kindle)

When I first started tinkering with JavaScript, object-oriented programming (OOP) was the rage, and JavaScript frequently was touted as one of the key object-oriented languages. After all, according to many online descriptions, almost everything within JavaScript “is OO.”

Now, in this enjoyable new book, JavaScript is hailed as a functional programming language. Of course, functional programming recently has been the rage in many programming circles. And “enjoyable” may seem an odd word to attach to a software text. Yet, it fits. Michael Fogus shows here that he is a technical writer who can be entertaining, effective and well-organized.

“This book,” he states, “is not about spewing dogma regarding the virtues of functional programming. I think there are many functional techniques that offer ways to rein in the complexities of software development, but I realize that at times, there are better ways to implement any given individual part.”

It is possible, of course, to debate object-oriented vs. functional JavaScript until the digital cows are called back home and put into infinite loops. But, for those who don’t know or care much about the differences, here are some basic views.

The Mozilla Developers Network (to simply pick  one example) discusses objected-oriented JavaScript on its site and declares: “Object-oriented programming may be seen as the design of software using a collection of cooperating objects, as opposed to a traditional view in which a program may be seen as a collection of functions, or simply as a list of instructions to the computer. In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects. Each object can be viewed as an independent little machine with a distinct role or responsibility.”

Meanwhile, HaskellWiki offers this explanation of functional programming: “In functional programming, programs are executed by evaluating expressions, in contrast with imperative programming where programs are composed of statements which change global state when executed. Functional programming typically avoids using mutable state.

“Functional programming requires that functions are first-class, which means that they are treated like any other values and can be passed as arguments to other functions or be returned as a result of a function. Being first-class also means that it is possible to define and manipulate functions from within other functions.”

Some of the programming languages typically labeled “functional” include Clojure, OCaml, Erlang,  Haskell, Scala, and F#.

Here is how Michael Fogus defines functional programming:

“As a bare-bones introduction, functional programming can be described in a single sentence:

Functional programming is the use of functions that transform values into units of
abstraction, subsequently used to build software systems.

“This is a simplification bordering on libel,” he continues, “but it’s functional (ha!) for this early stage in the book. The library that I use as my medium of functional expression in JavaScript is Underscore, and for the most part, it adheres to this basic definition.”

(Underscore.js can be obtained from http://underscorejs.org and imported into “the applicable project directories.”)

Fogus refuses, in his text, “to create a false dichotomy and say that functional and object-oriented styles should stand in opposition.” Indeed, he notes that JavaScript supports both models and “systems can and should be composed of both models.”

He also points out that JavaScript can be used with other paradigms, including imperative programming, prototype-based object-oriented programming, and metaprogramming.

“In no way does this book represent even a modicum of original thinking regarding functional programming in JavaScript,” he states. Yet, it is a worthy effort.

It is well written, smoothly organized, and nicely illustrated with short code examples and helpful diagrams. And Fogus notes that JavaScript does have “[l]anguage oddities, unsafe features, and a sea of competing libraries” that raise concerns when it is selected for a project. Functional programming, he contends, can be one way to help ensure that JavaScript “can be not only safe, but also simple to understand and test, in addition to being proportionally scalable to the size of the code base.”

Here is the chapter lineup for Fogus’s 237-page book:

  • Chapter 1. Introducing Functional JavaScript
  • Chapter 2. First-Class Functions and Applicative Programming
  • Chapter 3. Variable Scope and Closures
  • Chapter 4. Higher-Order Functions
  • Chapter 5. Function-Building Functions
  • Chapter 6. Recursion
  • Chapter 7. Purity, Immutability, and Policies for Change
  • Chapter 8. Flow-Based Programming
  • Chapter 9. Programming without Class

Functional JavaScript is a winner on at least two counts: (1) as a how-to text for long-time JavaScript programmers wishing to learn more about functional programming; and (2) as a how-to text for long-time functional programmers desiring to learn more about JavaScript.

The book is not recommended for JavaScript newcomers who are still at the level of typing console.log(“The answer to everything in the universe is 42”). However, experienced beginners can learn from it, and so can those of us who just tinker with JavaScript periodically and use it mainly to work with Node.js, Backbone.js, Ember.js, CoffeeScript, HTML and other choices.

Si Dunn