Attack of the Killer Parentheses: ‘Clojure in Action, 2nd Edition’ – #bookreview

Clojure in Action, 2nd Edition

Amit Rathore and Francis Avila

Manning – paperback

Clojure seems to be afflicted with a measles-like outbreak of parentheses, and it generally just looks strange to many software developers. And there’s a good reason for that, as this book’s two author point out in their recently released second edition.

“Clojure’s syntax is derived from its Lisp roots: lots of parentheses. It’s alien to most developers with experience in languages with Algol-inspired syntax like C, C++, Java, Python, Ruby, Perl, and so on.”

But Clojure also is an intriguing and powerful choice for many software development projects, Amit Rathore and Francis Avila insist. Clojure is “a functional Lisp on the JVM” (the Java Virtual Machine), and: “It is impossible to separate the Lisp, functional programming, and JVM features of Clojure. At every step they play on each other and tell a compelling software development story….”

I have been tinkering with Clojure on the side, at random spare moments, for more than two years, using a disorganized approach of looking at web postings, building and modifying simple projects that others have posted, and sometimes looking at Clojure how-to books as time permits.

From my perspective, Clojure in Action, 2nd Edition fills a beginner’s need for a friendly, well-organized approach to learning the language and putting it to work effectively. Developers already working with Clojure can benefit from having this book, too, as a handy reference. It covers a lot of ground, using reasonably short paragraphs and offers many short code examples to illustrate its key points.

Clojure in Action, 2nd Edition “assumes no prior experience with Lisp or with any functional programming language,” the authors emphasize. “It starts out with the absolute basics and slowly layers on the different features of the language in  a way to make it all fit together in an intuitive way. It takes a first-principles approach to all the topics, first explaining why something needs to be done a certain way, and only then talking about the Clojure way.”

Clojure is not a language for absolute beginners. The authors assume “you’re familiar with an OO [object-oriented] language like Java, C++, Ruby, or Python, but no background in Java, Lisp, or Clojure is required.” They also assume you have downloaded Clojure and gotten it working on your PC. You can read more about Clojure and download it here.

This expanded 2nd edition states that it covers the “new” features of Clojure 1.6. Of course, Clojure already is up to 1.8, but I have tried many of the code examples at various points in the book and have not encountered problems while running 1.8.

Si Dunn

Elixir in Action: A good guide to the ‘alternative language for the Erlang virtual machine’ – #programming #bookreview



Elixir in Action

Saša Jurić

Manning – paperback

“Elixir,”  Saša Jurić writes, “is a modern functional programming language for building large-scale, distributed, fault-tolerant systems for the Erlang virtual machine.”

What Elixir really is, of course, is a breath of fresh air for software developers who find it hard or confusing to work with Erlang’s sometimes complicated syntax and conventions.

Erlang has long been almost off the chart–the bottom of the chart–when computer languages are stacked up by popularity.  It began its oddball life in the 1980s as a programming language for the computers in telephone switching systems, specifically Swedish-made, Ericsson telephone switching systems.

Indeed, I first encountered Erlang in the  late 1980s while trying to help Ericsson sell Swedish-made computers to American banks. Back then, I counted my lucky stars that I didn’t have to learn it, because I was a tech writer, not a software developer.

Today, however, Erlang and its Open Telecom Platform (OTP) libraries are gaining new converts among serious practitioners of functional programming. Many of them likewise are drawn to Erlang’s built-in support for concurrency, distribution and fault tolerance.

The digital Swedish meatball known as Erlang turns out to be a powerful choice for providing high reliability and scalability to networked and distributed systems with multi-core processors. Telephone networks require high reliability and flexible scalability. And Erlang was designed to help provide both — without limiting itself to telecom systems.

Some of Erlang’s lack of popularity can be blamed on the language’s somewhat difficult learning curve. But it also has not been heavily promoted to software developers. That has been changing recently as companies and developers learn more about Erlang’s good track record, Saša Jurić points out.

“It powers various large systems and has been doing so for more than two decades, such as the WhatsApp messaging application, the Riak distributed database, the Heroku cloud, the Chef deployment automation system, the RabbitMQ message queue, financial systems, and multiplayer backends. It’s truly a proven technology.”

In Elixir in Action,  Saša Jurić nicely meets his goal of writing a book that brings “programmers new to Elixir and Erlang to the point where they can develop complex systems on their own.” Elixir provides an alternative language based on several other languages, including Ruby and Clojure, as well as Erlang.

Jurić’s how-to guide requires no prior experience with either Erlang or Elixir, but you should be familiar with at least one other programming language, such as JavaScript, C# or Ruby.

His book is divided into three parts:

  • Part 1, “The Language,” offers a high-level overview of Erlang and Elixir. Then it delves into Elixir’s basic building blocks and details common functional programming idioms.
  • Part 2, “The Platform,” focuses on primary aspects of BEAM, the Erlang virtual machine, as well as “how concurrency works and how it can help you build reliable systems.” Indeed, “[c]oncurrency is at the heart and soul of Erlang systems,” Jurić writes. “Almost every nontrivial Erlang-based production system is highly concurrent. Even the programming language is sometimes called a concurrency-oriented language.”
  • Part 3, “Production,”discusses “production aspects of BEAM-powered systems,” as well as “how to package components, reuse third-party libraries, and build a simple web server,” and “how to build a deployable standalone release and how to interact with the running system.”

Elixir in Action does not cover everything. But it provides fine overviews, clear how-to instructions, and compact code examples that illustrate important points. It can get you going in good directions.

“Elixir,” the author emphasizes, “lowers the entry barrier into the Erlang world and improves developer productivity.”

 — Si Dunn


The Joy of Clojure – This fine 2nd edition makes learning a Lisp dialect fun (well, almost) – #bookreview


The Joy of Clojure, 2nd Edition

Michael Fogus and Chris Houser

(Manning – paperback)

Several times, I had played with Clojure and considered learning it. But I kept deciding it looked too weird, required too many parentheses and put its operators in strange places. Furthermore, it has always ranked low on the assorted lists of currently “popular” programming languages.

So I moved on and put my focus elsewhere. Indeed, I ignored the first edition of this book. But I am now glad that I have had a chance to reconsider Clojure and to review this new edition from Manning.

The book by Michael Fogus and Chris Houser is intelligently and pleasantly written, and the authors do an excellent job of explaining (and “selling”) Clojure to skeptics like me. Compared with many other programming languages, Clojure is compact. And, it is focused primarily on functional and declarative programming. Also, it offers excellent support for concurrency (where several computations are performed during overlapping time periods rather than waiting for one-at-a-time sequences to complete).

Clojure looks weird because it is one of the several dialects of Lisp, which first appeared in 1958. But Clojure runs on the Java Virtual Machine and JavaScript runtimes. And, it is a functional programming language that has gained a good reputation for being fast and stable. Along with its built-in concurrency support, Clojure also offers the “predictable precision” of immutable and persistent data structures.

The Joy of Clojure is not a book for absolute beginners. Still, Clojure is very easy to install (I have it running on a Windows PC and a Linux PC). And the book’s code examples work well with Clojure’s Read-Eval-Print Loop (REPL).

I am still not convinced there is a lot of “joy” in learning one of the Lisp dialects. Yet, with this fine book as a guide, I am getting a better feel for Clojure and its excellent possibilities. (For example, its compactness and concurrency support likely will make it a lot more popular soon.) And I am enjoying the authors’ text and code examples, even though the latter still look strange as I key them in and modify them to get new results–or error messages.

Bottom line, I am pleased to recommend The Joy of Clojure to others who have been curious but resistant. Resistance is, after all, futile.

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 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

JavaScript as Compilation Target: ClojureScript and Dart – #programming #bookreview

Despite its widespread success, JavaScript has a reputation for being a computer language with many flaws. Still, it is now everywhere on the planet, so it is here to stay, very likely for a long, long time.

Not surprisingly, several new languages have emerged that jump over some of JavaScript’s hurdles, offer improved capabilities, and also compile to optimized JavaScript code.

Two of these languages are the focus of noteworthy new “Up and Running” books from O’Reilly: ClojureScript: Up and Running and Dart: Up and Running.

Here are short reviews of each book:

ClojureScript: Up and Running
Stuart Sierra and Luke VanderHart
(O’Reilly, paperback, Kindle)

ClojureScript, the authors contend, “provides developers with a language that is more powerful than JavaScript, which can reach all the same places JavaScript can, with fewer of JavaScript’s shortcomings.”

The primary targets of ClojureScript are “web browser applications, but it is also applicable to any environment where JavaScript is the only programmable technology available,” they add.

“ClojureScript is more than Clojure syntax layered on top of JavaScript: it supports the full semantics of the Clojure language, including immutable data structures, lazy sequences, first-class functions, and macros,” they emphasize.

Their 100-page book focuses on how to use ClojureScript’s features, starting at the “Hello world” level and gradually advancing to “Development Process and Workflow” and “Integrating with Clojure.” (ClojureScript is designed for building client-side applications, but it can be merged with Clojure on the JVM to create client-server applications.)

Early in the book, they also describe how to compile a ClojureScript file to JavaScript and emit code “that is fully compatible with the Advanced Optimizations mode of the Google Closure Compiler.”

The two writers are Clojure/ClojureScript developers with a previous book to their credit.

ClojureScript: Up and Running is written well and appropriately illustrated with code samples, flow charts, and other diagrams. The authors recommend using the Leiningen build system for Clojure, plus the lein-cljsbuild plug-in for ClojureScript.

Their book is a smooth introduction to ClojureScript that requires no prior knowledge of Clojure. But you do need a basic working knowledge of JavaScript, HTML, CSS, and the Document Object Model (DOM).


Dart: Up and Running
Kathy Walrath and Seth Ladd
(O’Reilly, paperback, Kindle)

Google created Dart to be “an open-source, batteries-included developer platform for building structured HTML5 web apps,” the two authors note.

Dart provides not only a new language, but libraries, an editor, a virtual machine (VM), a browser that can run Dart apps natively, and a compiler to JavaScript.”

Indeed, Dart looks very similar to JavaScript and is “easy to learn,” the two writers state. “A wide range of developers can learn Dart quickly. It’s an object-oriented language with classes, single inheritance, lexical scope, top-level functions, and a familiar syntax. Most developers are up and running with Dart in just a few hours.”

The authors work at Google and note that some of the software engineers who helped develop the V8 JavaScript engine that is “responsible for much of Chrome’s speed” are now “working on the Dart project.”

Dart has been designed to scale from simple scripts all the way up to complex apps, and it can run on both the client and the server.

Those who choose to code with Dart are urged to download the open-source Dart Editor tool, because it also comes with a “Dart-to-JavaScript compiler and a version of Chromium (nicknamed Dartium) that includes the Dart VM.”

Since Dart is new, the writers also urge readers to keep an eye periodically on the Dart website and on their book’s GitHub site, where code can be downloaded and errors and corrections noted.

Dart: Up and Running is a well-structured, well-written how-to book, nicely fortified with short code examples and other illustrations. While the book appears very approachable and simple, it is not for complete beginners. You should have a basic working knowledge of JavaScript, HTML, CSS, and the Document Object Model (DOM).

If you are looking for a web development language that matches JavaScript’s dynamic nature but also addresses JavaScript’s sometimes-aggravating shortcomings, consider trying Dart—with this book in hand.

Si Dunn

Programming Clojure, 2nd Edition – The virtues of concurrency and functional style – #bookreview #in #programming

Programming Clojure, 2nd Edition
Stuart Halloway and Aaron Bedra
(Pragmatic Bookshelf,
paperback, list price $35.00)

Clojure is yet another computer programming language with an odd name and many followers.

For example, Dr. Venkat Subramaniam, an award-winning author and founder of Agile Developer, Inc., has called Clojure “a beautiful, elegant, and very powerful language on the JVM [Java Virtual Machine].”

A lot has happened to Clojure (pronounced like “closure”) since the first edition of this book was published in 2009. Clojure has been updated several times and gained some enhancements, a lot of new followers, and many libraries.

Programming Clojure, 2nd Edition has been rewritten and reorganized to cover these new features, concepts and developments.

“Clojure is a powerful, general-purpose programming language,” the authors note. But this is not a book for raw beginners, even though its first chapter does start at the traditional “Hello, world” level. It is intended for “experienced programmers looking for power and elegance.” You should have some experience with C#, Java, Python, or Ruby before tackling Clojure.

“Clojure is built on top of the Java Virtual Machine, and it is fast,” Halloway and Bedra emphasize. “This book will be of interest of Java programmers who want the expressiveness of a dynamic language without compromising on performance.”

They add: “If you program in Lisp, use a functional language such as Haskell, or write explicitly concurrent programs, you will enjoy Clojure.”

Indeed, Clojure’s creator, Rick Hickey, emphasizes the language’s value as an alternative to the “complexity” introduced in object-oriented programming. “Object-oriented programming seems easy,” he states, “but the programs it yields can often be complex webs of interconnected mutable objects.”

He continues: “Functional programming offers an alternative. By emphasizing pure functions that take and return immutable values, it makes side effects the exception rather than the norm. Clojure is designed to make functional programming approachable and practical for commercial software developers.”

Clojure also makes concurrent programming easier. “Many languages build a concurrency model around locking, which is difficult to use correctly,” the authors point out. “Clojure provides several alternatives to locking: software transactional memory, agents, atoms, and dynamic variables.”

The 268-page book is well-organized and well written, and it offers numerous practical code examples. The book also has been reviewed for technical accuracy by a panel of Clojure practitioners.

Clojure code, incidentally, tends to be short (but you do need an editor that can “at least indent code correctly and can match parentheses”).

In one of the book’s comparison examples, the function produced by a 14-line sample of Java code is duplicated in Clojure with just two lines. So development in Clojure potentially can be fast.

Si Dunn