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

Advertisements

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

 

Java 8 in Action – Ready for lambdas, streams and functional-style programming? #bookreview

 

Java 8 in Action

Lambdas, streams, and functional-style programming

Raoul-Gabriel Urma, Mario Fusco, Alan Mycroft

(Manning – paperback)

 Java 8, we were sometimes assured, would just be Java 7 with a few slick new (or past-due) features added.

Actually, now that it’s here, Java 8 represents “the biggest change to Java in the 18 years since Java 1.0 was released,” the three authors of this fine new book point out.

Of course, news of “big changes” seldom sits well with developers who have spent countless hours learning and getting comfortable with one particular version of a programming language.

And many coders and companies will continue sticking with Java 7 for a while longer, because it still works. But the adoption pace for Java 8 keeps picking up. So, to misquote an old sci-fi slogan, resistance soon will become somewhat futile.

Lambdas, streams, and functional-style programming capabilities are Java 8’s headline additions. And there are some other major and minor additions, as well, including default methods and a new Date and Time API.

Java 8 in Action does an excellent job of introducing these new capabilities, and the book offers many short code examples and other illustrations to show how to put the new Java 8 capabilities to work.

Indeed, short (and shorter!) code is one of the hallmarks of Java 8. “In Java 8 you can write more concise code that reads a lot closer to the problem statement,” the writers emphasize. To illustrate that point, they offer a five-line example of verbose Java 7 code and follow it with a one-line Java 8 code example that accomplishes the same thing. Other examples also drive home the coding efficiencies that Java 8 can offer.

Lambdas, also known as anonymous functions, enable you to skip writing method definitions that will only be used once. The authors note that “passing code is currently tedious and verbose in Java [meaning 7 and earlier]. Well, good news! Lambdas fix this problem: they let you pass code in a concise way. Lambdas technically don’t let you do anything you couldn’t do prior to Java 8. But you no longer have to write clumsy code using anonymous classes to benefit from behavior parameterization!”

The new Streams API makes it much easier to work with collections in Java and provides “a much different way to process data in comparison to the Collections API.” Using the Streams API, “you don’t need to think in terms of loops at all. The data processing happens internally inside the library.”

Meanwhile, if you are a diehard object-oriented programmer, you may be leery of the term “functional programming” and the notion of using functions as values. (“In practice, you can’t completely program in pure functional style in Java,” the authors note. Instead, you will learn how to write “functional-style programs” in which you hide the side effects.)

With Java 8, “two core ideas from functional programming…are now part of Java: using methods and lambdas as first-class values, and the idea that calls to functions or methods can be efficiently and safely executed in parallel in the absence of mutable shared state. Both of these ideas are exploited by the new Streams API,” the writers state.  Also, in Java 8, they add, “there’s an Optional class that, if used consistently can help you avoid NullPointer exceptions.”

This review barely dents the surface of this excellent how-to book’s contents. Whether you are learning Java now or you are a Java developer who wants to keep your coding skills up-to-date and sharp, Java 8 in Action should be a book you will read soon.

Si Dunn

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

fogus2_cover150

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

Making Sense of NoSQL – A balanced, well-written overview – #bigdata #bookreview

Making Sense of NoSQL

A Guide for Managers and the Rest of Us
Dan McCreary and Ann Kelly
(Manning, paperback)

This is NOT a how-to guide for learning to use NoSQL software and build NoSQL databases. It is a meaty, well-structured overview aimed primarily at “technical managers, [software] architects, and developers.” However, it also is written to appeal to other, not-so-technical readers who are curious about NoSQL databases and where NoSQL could fit into the Big Data picture for their business, institution, or organization.

Making Sense of NoSQL definitely lives up to its subtitle: “A guide for managers and the rest of us.”

Many executives, managers, consultants and others today are dealing with expensive questions related to Big Data, primarily how it affects their current databases, database management systems, and the employees and contractors who maintain them. A variety of  problems can fall upon those who operate and update big relational (SQL) databases and their huge arrays of servers pieced together over years or decades.

The authors, Dan McCreary and Ann Kelly, are strong proponents, obviously, of the NoSQL approach. It offers, they note, “many ways to allow you to grow your database without ever having to shut down your servers.” However, they also realize that NoSQL may not a good, nor affordable, choice in many situations. Indeed, a blending of SQL and NoSQL systems may be a better choice. Or, making changes from SQL to NoSQL may not be financially feasible at all. So they have structured their book into four parts that attempt to help readers “objectively evaluate SQL and NoSQL database systems to see which business problems they solve.”

Part 1 provides an overview of NoSQL, its history, and its potential business benefits. Part 2 focuses on “database patterns,” including “legacy database patterns (which most solution architects are familiar with), NoSQL patterns, and native XML databases.” Part 3 examines “how NoSQL solutions solve the real-world business problems of big data, search, high availability, and agility.” And Part 4 looks at “two advanced topics associated with NoSQL: functional programming and system security.”

McCreary and Kelly observe that “[t]he transition to functional programming requires a paradigm shift away from software designed to control state and toward software that has a focus on independent data transformation.” (Erlang, Scala, and F# are some of the functional languages that they highlight.) And, they contend: “It’s no longer sufficient to design a system that will scale to 2, 4, or 8 core processors. You need to ask if your architecture will scale to 100, 1,000, or even 10,000 processors.”

Meanwhile, various security challenges can arise as a NoSQL database “becomes popular and is used by multiple projects” across “department trust boundaries.”

Computer science students, software developers, and others who are trying to stay knowledgeable about Big Data technology and issues should also consider reading this well-written book.

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

Introducing Erlang – A gentle, effective guide to a challenging programming language – #bookreview

Introducing Erlang
Simon St. Laurent
(O’Reilly – paperback, Kindle)

Erlang has come a long way since it began its odd life in the 1980s as a programming language for telephone switching systems, specifically Swedish-made, Ericsson telephone switching systems.

Today, the language and its Open Telecom Platform libraries are gaining new converts among serious practitioners of functional programming. Many of them likewise are drawn to the built-in support for concurrency, distribution and fault tolerance.

“The broad shift from single computers to networked and distributed systems of multiprocessor-based computing gives the Erlang environment a tremendous advantage over practically every other environment out there,” author Simon St. Laurent contends. “More and more of the computing world is starting to face exactly the challenges that Erlang was built to address.” Yet, as he concedes in his preface, “Erlang has long been a mysterious dark corner of the programming universe, visited mostly by developers who need extreme reliability or scalability and people who want to stretch their brains.”

Brain-stretching indeed is one reason why Erlang has stayed in that dark corner for more than two decades.

The language’s learning curve, St. Laurent notes, “starts gently for a while, then it gets much steeper as you realize the discipline involved, and then goes nearly vertical for a little while as you try to figure out how that discipline affects getting work done—and then it’s suddenly calm and peaceful with a gentle grade for a long time as you reapply what you’ve learned in different contexts.”

In a world where everything seemingly must be done in a hurry, you won’t learn Erlang in a hurry. But the payoff for learning it can be rewarding. Erlang, it seems, now is on a roll and experiencing growing demand. The language has been showing up in many different places, from Facebook to CouchDB to the Costa Rican Institute of Technology, to name just a few. Numerous package managers, such as Debian, MacPorts, and Ubuntu, also include a version of Erlang in their default installation.

I run Windows machines, and getting Erlang onto them has proved pleasingly easy. Indeed, Windows users apparently have some of the easiest times getting started with Erlang. Just go to http://erlang.org/download.html and click on the correct link – 32-bit or 64-bit – for your PC.

The book’s code samples can be downloaded from a link provided in the book. And it’s easy to work with the Erlang shell, its command-line interface. The newest version now provides numbered lines.

But, if you’ve worked with other programming languages, Erlang’s syntax likely will seem awkward and strange for a while.

“Punctuation is different and capitalization matters,” the author emphasizes. “Periods even get used as conclusions rather than connectors!”

To display the current working directory in the shell, for instance, you type pwd(). And do not forget to include the period.

To move up a directory, you type cd(“..”). And do not forget to include both the quotation marks and the concluding period.

Indeed, almost everything you enter in Erlang seemingly must end with a period.

Also: “Forget classes, forget variables that change values—even forget the conventions of variable assignment,” the author cautions. “Instead, you’re going to have to think about pattern matching, message passing, and establishing pathways for data rather than telling it where to go.”

Introducing Erlang takes a slow and gentle but effective approach to learning this powerful and difficult language. Simon St. Laurent spends a lot of time trying to help readers “get comfortable in the sunny meadows at the bottom of the learning curve.” Still, his well-written book effectively and efficiently meets its stated goal of helping you “learn to write simple Erlang programs.” It likewise shows and explains how to get started working with the OTP, the Open Telecom Platform’s libraries.

The book and its numerous code examples offer a solid grounding in the basics that you can then use to “understand why Erlang makes it easier to build resilient programs that can scale up or down with ease.” And, if you decide to continue learning, Simon St. Laurent’s new book can make it easier for you to move on to the really brain-stretching, and shadowy, inner workings of Erlang.

Si Dunn