JavaScript Application Design: A book you likely need if you are working with, or still learning, JavaScript – #programming #bookreview

JavaScript Application Design

A Build First Approach

Nicolas Bevacqua

Manning – paperback

 

I didn’t know how much I needed this book until I started reading it and exploring its code examples.

Many of us who have worked with JavaScript started our connections to the language in very haphazard fashions. We learned some of it on the job, under deadline pressure to fix or update somebody else’s code. Or we took an introductory class or two and then started picking up whatever else we could on the fly, including the bad habits of others around us who seemed to know a bit more about JavaScript than we knew at the moment.

Unfortunately, JavaScript is a big, messy programming language, and it offers numerous opportunities to crash and burn if you really don’t know what you are doing.

In his new book, JavaScript Application Design, Nicolas Bevacqua makes a compelling case for using “the Build First philosophy of designing for clean, well-structured, and testable applications before you write a single line of code.”

He writes: “You’ll learn about process automation, which will mitigate the odds of human error…. Build First is the foundation that will empower you to design clean, well-structured, and testable applications, which are easy to maintain and refactor. Those are the two fundamental aspects of Build First: process automation and design.”

In his well-written text, he argues: “Front-end development requires as much dedication to architecture planning and design as back-end development does. Long gone are the days when we’d copy a few snippets of code off the internet, paste them in our page, and call it a day. Mashing together JavaScript code as an afterthought no longer holds up to modern standards. JavaScript is now front and center.”

He continues: “We have many frameworks and libraries to choose from, which can help you organize your code by allowing you to write small components rather than a monolithic application. Maintainability isn’t something you can tack onto a code base whenever you’d like; it’s something you have to build into the application, and the philosophy under which the application is designed, from the beginning. Writing an application that isn’t designed to be maintainable translates into stacking feature after feature in an ever-so-slightly tilting Jenga tower.”

Bevacqua divides his nine-chapter book into just two parts: build processes and managing complexity. Here is how the chapters are organized:

  • PART 1: BUILD PROCESSES
    1 – Introduction to Build First
    2 – Composing build tasks and flows
    3 – Mastering environments and the development workflow
    4 – Release, deployment, and monitoring
  • PART 2: MANAGING COMPLEXITY
  • 5 – Embracing modularity and dependency management
    6 – Understanding asynchronous flow control methods in JavaScript
    7 – Leveraging the Model-View-Controller
    8 – Testing JavaScript components
    9 – REST API design and layered service architectures

Bevaqua notes that “Linting is often referred to as the first test you should set up when writing JavaScript. Where linters fail, unit tests come in.” He strongly pushes testing and automation right from the start.

Linting soon leads to Grunt, which Bevaqua uses as a task runner and key build tool (with selected modules) in this book. “Grunt is a tool that allows you to write, configure, and automate tasks–such as minifying a JavaScript file or compiling a LESS style sheet–for your application,” he states. (It also works well on Windows machines, which I find handy.)

Grunt leads to running a bit of Node.js on the command line. And if you’ve never worked with Node.js, Bevacqua takes the reader smoothly through the process of installing it and using it in linting exercises. Indeed, he devotes an entire appendix (B) to installing and running Grunt and picking the right plugins for the right tasks and targets.

One of the best parts of this book, to me, is how the author uses short code examples to introduce a concept, and  then builds upon the examples with helpful descriptions and more short but expanded code samples.

Nicolas Bevacqua offers his readers plenty of helpful how-to and why information. Using his book, I have begun applying the Build First approach to some new projects and learning to how test and automate more of my work. I feel as if I now have a good shot at getting a lot better at JavaScript.

There is one small but important glitch to note: At two points in my preview copy of the book from Manning, Bevacqua shows what he calls a simple way to create bare-minimum JSON manifest files. For example, echo “{}” > package.json. Creating a blank, starting-point manifest file did not work this way for me. Instead, I had to use echo {“name: ” “project-name”} > package.json. The empty package.json issue apparently is somehow related to certain versions of Node’s npm.

Si Dunn 

Advertisements

NODE.js IN PRACTICE – A well-focused guide to understanding & using this powerful web development platform – #programming #bookreview

 

Node.js in Practice

Alex Young and Marc Harter

Manning – paperback

I have had a long-term, love-ignore relationship with Node.js. I have taken Node classes, read Node books, and tinkered with Node programming both on Windows and Linux machines. Sometimes I have loved working with Node.js. Other times, I have ignored it for months at a stretch while I rush around trying out other choices and development distractions: Clojure, Erlang, Grails, Hadoop, and Ember.js, for example — the list goes on and on.

Node.js in Practice is aimed at intermediate Node.js programmers and even advanced Node.js programmers. There is some awareness that beginners also may be reading this book. So the authors start by explaining Node from the standpoint of “what it is, how it works, and why it’s something you can’t live without.” Then they quickly recommend that Node newcomers should stop for now and read another good, but more basic, how-to book first: Node.js in Action.

In Node.js in Practice, the learning curve can start getting steep fairly quickly, especially for those of us who have worked somewhat superficially with Node in web projects that also involve other software (such as the MEAN stack: MongoDB, Express and AngularJS, plus Node). Fortunately, the authors, Alex Young and Marc Harter, take a very focused, three-part approach that keeps Node.js centered in the spotlight and promotes deeper understanding.

Part One focuses on “Node’s core fundamentals” and “what’s possible using only Node’s core modules (no third-party modules).” Part Two moves into “real-world development recipes” and shows how to “master four highly applicable skills—testing, web development, debugging, and running Node in production.” Some third-party modules also are introduced. Part Three, meanwhile, emphasizes “creating your own Node modules in a straightforward manner that ties in all kinds of ways to use npm commands for packaging, running, testing, benchmarking, and sharing modules. It also includes helpful tips on versioning projects effectively.”

The book offers “115 techniques…each module covering a specific Node.js topic or task, and each divided into practical Problem/Solution/Discussion sections.” I really like this approach, and the illustrated discussions that accompany each short code example are especially helpful.

For me, it has been a pleasure to upgrade to the latest version of Node.js and reconnect with it using this new book. Despite my previous experience with Node.js, I see a lot to learn! My thanks to Manning for providing a review copy of Node.js in Practice.

 

Node.js Blueprints – A good how-to book that covers plenty of JS frameworks and tools – #programming #bookreview

7338OS_Node.js Blueprints (1)

 

Node.js Blueprints

Develop stunning web and desktop applications with the definitive Node.js

Krasimir Tsonev

(Packt Publishing paperback, Kindle)

 

Krasimir Tsonev’s new Node.js Blueprints book has proven helpful for me as I try to become more adept at using Node.js and a few of the many software packages that can work with it, such as AngularJS, Backbone.js, Ember.js, ExpressJS, Grunt.js and Gulp.js.

If you’ve never used Node.js before, here is its official description from the Nodejs.org site operated by Joyent, Inc.:

“Node.js is a platform built on Chrome’s JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.”

The focus of Node.js Blueprints is on showing readers the basics of how to use various frameworks, libraries and tools that can help them develop real-world applications that run with Node.js.

Tsonev’s approach is to introduce several popular frameworks, libraries and tools, provide code examples and explain the roles of various sections or modules within the code. The goal in each chapter is to help the reader learn how to work with a framework or other package and create a simple application — a blueprint for something bigger — that can run with Node.js

The book is aimed at intermediate-level JavaScript developers, especially “web developer[s] with experience in writing client-side JavaScript,” who are interested in using Node.js in web and desktop applications.

The 12-chapter, 268-page book is structured as follows:

  • Chapter 1, Common Programming Paradigms, focuses on how “common design patterns known in JavaScript” can be applied in Node.js, as well.
  • Chapter 2, Developing a Basic Site with Node.js and Express, shows how to use ExpressJS, “one of the top frameworks on the market,” in applications “using the built-in Express modules and…your own modules.”
  • Chapter 3, Writing a Blog Application with Node.js and AngularJS, explains how to use the Angular frontend framework with Node.js, MongoDB and MySQL to create “a dynamic application that works with real databases.”
  • Chapter 4, Developing a Chat with Socket.IO, points out that “every big web app uses real-time data” and how it is “important to show instant results to the users.” And it covers “the creation of a simple real-time chat,” while emphasizing that “[t]he same concept can be used to create an automatically updatable HTML component.”
  • Chapter 5, Creating a To-do Application with Backbone.js, notes that “Backbone.js was one of the first frameworks that introduced data binding at the frontend of applications.” A simple (but useful) to-do application is used to illustrate how to use the powerful framework along with Node.js.
  • Chapter 6, Using Node.js as a Command-line Tool, explains that many command-line tools have been written with Node.js, and this chapter shows how to create one. The result is “a simple application which grabs all the images in a directory and uploads them to Flickr.”
  • Chapter 7, Showing a Social Feed with Ember.js, is centered on producing “an Ember.js example that will read a Twitter feed and display the latest posts. That’s actually a common task of every developer,” Tsonev says, “because a lot of applications need to visualize social activity.” (Reviewer’s caution: Ember.js has a long learning curve, and this chapter just barely gets you started.)
  • Chapter 8,  Developing Web App Workflow with Grunt and Gulp, explains how to use two popular task runners. “Grunt is the de facto standard” for simplifying and managing tasks such as concatenation, minification, templating and other operations before an application is delivered to users. Gulp, meanwhile, is a popular build system. The projects in this chapter include generating a cache manifest file using Grunt, and concatenating and minifying using Gulp.
  • Chapter 9, Automating Your Testing with Node.js, is especially aimed at fans (and forced-by-employer “enthusiasts”) of test-driven development and behavior-driven development. The chapter introduces how to use the Node.js versiosn of the Jasmine and Mocha frameworks for testing JavaScript code and how to use the headless browser PhantomJS to test user interfaces. You also are shown how to use DalekJS, a Node.js module that allows you to control major browsers such as Google Chrome, Internet Explorer and Firefox while doing interface tests.
  • Chapter 10, Writing Flexible and Modular CSS, emphasizes how “[t]he Web is built on the basis of three languages–HTML, CSS, and JavaScript” and “Node.js provides really helpful instruments to write CSS…and improve our style sheets.” Other topics include the Less preprocessor, the Stylus preprocessor, the Sass preprocessor, and the AbsurdJS preprocessor.
  • Chapter 11, Writing a REST API, focuses on building a Representational State Transfer (REST) Application Programming Interface (API). The chapter’s Node.js project is “an API of a simple online books library. The resources are the books, and they will be accessed through the REST API.” Tsonev notes that “Node.js is very often used to build REST APIs. Also, because it is a common tool, we have several possible approaches.” In this chapter, however, the emphasis is “to build our REST API from scratch, because it will be more interesting and challenging.”
  • Chapter 12, Developing Desktop Apps with Node.js, declares that “Node.js can be used to produce desktop programs, and w don’t have to learn a new language or use a new tool.” In this chapter, Tsonev shows how to use node-webkit to create a file browser that runs as a desktop program, reads files from the hard drive, displays the files on-screen, and also displays images.

Tsonev’s well-written book introduces a lot of good material to help you get started. After that, you have to do the work to get better at using the various frameworks and tools. But the writer gives you plenty of possibilities to start with in your quest to become a better developer.

You may encounter an occasional typo in the book’s printed code. Thus, be sure to download the available code examples for reference, even if you prefer to type in code by hand (one of my favorite ways to learn, too).

And, during the lengthy process to write, edit, and publish the book, some of the software has changed to newer versions than are called for in the text–which may affect how something works in certain small areas of code.  Indeed, in programming books that rely on several different software packages, changes always happen, and those changes seldom are convenient to the printing deadline.

So if something doesn’t work the way you expect, and you are positive your hand-typed code has no known mistakes, don’t yell at the author. Download the code examples. Look for the publisher’s errata files. Seek out comments at book sites such as the readers’ reviews on Amazon, as well as comments on social media sites and specialized sites where JavaScript and Node.js developers hang out. Also take a look at the “official” websites for the frameworks and tools.

I have been wanting to learn more about working with Node.js, and Node.js Blueprints definitely is filling that need.

Si Dunn

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

 

Instant Handlebars.js – A short but effective how-to guide – #programming #bookreview

Instant Handlebars.js

Learn how to create and implement HTML templates into your projects using the Handlebars library
Gabriel Manricks
(Packt Publishing – e-book, paperback)

“Short, fast, and focused.” These are the three promises offered for Gabriel Manricks’ new book, Instant Handlebars.js, from Packt Publishing. And, at just 62 pages in print format, it lives up to those vows.

Manricks explains and demonstrates Handlebars using five well-structured sections. First, he introduces Handlebars.js and describes what a templating engine is and does. He notes that “[t]he purpose of using a templating engine such as Handlebars is to generate some kind of viewable content (usually HTML pages), dynamically.” He then shows how to download the Handlebars library and create a “Hello {{name}}” template and a simple helper.

His “Top 6 Features you need to know about” section goes to the heart of Handlebars.js and shows how you can organize large projects and pre-compile templates.

The Top 6 topics include: (1) Expressions—“the core of templates”; (2) Helpers—“[t]hese are where Handlebars gets its extendibility”; (3) Partials—“the building blocks of the template world” and important for modular design; (4) Structuring a Handlebars app—the pros and cons of various potential structures; (5) Pre-compilation—which can lead to “a more optimized and efficient site”; and (6) Logging and comments—“writing clear and debug-able templates and helpers, so you can easily test and maintain them in the future.”

In the book’s final section, “People and places you should get to know,” Manricks describes some individuals and websites you should follow so you can “stay up to date and dive deeper into the Handlebars community.”

Despite its small page count, the book contains numerous short code examples that show how to put Handlebars.js to work in HTML files.

You need at least some modest experience with JavaScript and HTML to get full benefit from this book. You also will make brief use of Node.js to install Handlebars.js.

If you have done any work with Ember.js, you already have picked up some Handlebars.js experience. However, even here, this short, handy guide can help you get a better understanding of how to use Handlebars, with or without Ember.

Instant Handlebars.js can be ordered in e-book or paperback format direct from Packt Publishing’s website. Or, the Kindle version and the paperback can be ordered via Amazon.

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

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