Posted on by & filed under Content - Highlights and Reviews, Programming & Development, Web Development.

Programming is a nasty way to lose your mind. Each 12-hour day is a mental beat-down of incorrect assumptions, understandings and actions. Software, our opponent, is an ever changing, multi-tentacled horror of complexity. In one noodley appendage she wields configuration, yet in another: a business domain – a whirling fury of operating system, versioning, incompatibilities, obsolescences, upgrades, syntax and semantics. All we have with which to face her is our chosen language – itself software! Escher, meet Cthulhu (tentacled monsters wrapped-up, tiled and reflected out to infinity). Clojure is the sword-of-simplicity that can defeat this monster so you can retain your sanity.

Simple made Easy

Rich Hickey, Clojure’s creator, expresses how simplicity can aid us in creating software correctly, and even joyfully. In this blog post, we’ll explore uniformity as one of the main manifestations of simplicity. Read more about The Clojure Way in The Joy of Clojure.


Clojure, as a lisp, has a searingly uniform syntax, which for new-comers is unfamiliar and discomforting; it seems backwards. Each expression is surrounded by parentheses and the first symbol within the parentheses is the verb. This syntax creates uniformity. For instance, in many languages all three of these calling conventions are valid:

With these conventions you have to remember, or check the docs, to know when each is appropriate. In Clojure it’s always (verb a b). This helps reduce the cognitive load when learning new libraries, or even when reading familiar code.

More than that, it enables serious meta programming. As the structure of the text has a known form, you can program against it, which is why macros in lisps are so much more powerful than in non-lisps.

Statements and Expressions

Clojure code consists uniformly of expressions – there are no statements. So, what is the difference? Statements have no value – they do not evaluate to anything, whereas expressions return a value. For instance:

This is a flow control statement. When it runs, either this or that happens, but the block does not evaluate to anything. The block itself is not a value, so you can’t put a handle on it. Although in Clojure:

This evaluates, concretely, to this or that value. The virtue is that expressions, because they are values, can fit almost anywhere in your code, and hence compose.

This composition enables a fluent style of code, where values flow between operations. Furthermore, because its in the language, it’s everywhere.

This is an element of what Rich calls value-oriented programming.

Higher order functions

In Clojure, code snippets with the same intent appear uniformly. That is, if two bits of code do the same thing, they’ll be the same, which is not generally the case.

Consider the workhorse of many languages, the venerable for loop. The
problem with it is that anything can go within it, and entire classes of bugs exist around loop counters and their nasty tendency to be off by one. More than that, to understand what any given for loop is doing, you must unpick it and literally run it in your head.

Consider the job of adding one to every element of a vector:

The incidental complexity here is enormous! In Clojure you have:

Now consider summing that collection:

This for loop looks very similar to the last one, but its purpose is altogether different. In Clojure this is expressed as:

You might say, “but my language gives me x.sum()“. You need to rely, however, on the particular collection providing that particular functionality you want, and are you sure it’s not or maybe sum(x)?

The point is not that the code is shorter (helpful as that is), but that the semantic is made clear by the code. These higher order functions can be thought of as the for loop patterns. Map is a for loop that does something to every element of the collection, reduce builds a single value from a collection, filter filters a collection, and so on. Indeed, Clojure provides a wealth of these functions for interleaving, partitioning, shuffling sequences and hence collections.

Here the uniformity is not so obvious as using for everywhere seems uniform. But the uniformity is of the semantic not just the syntax: the same pattern gets the same name everywhere, which helps reduce complexity and enable understanding.


This has been a fast and loose discussion of some of the aspects of uniformity in Clojure and how they empower the language and programmer. We have seen how uniformity of syntax enables the powerful meta-programming of lisps, how being comprised uniformly of expressions is critical for value-oriented programming, and finally, how recognizing and treating common patterns uniformly undergirds higher-order functions.

Taken individually, these elements are useful, but not life changing. Everything in code, however, is combinatorial, and so the reduction in complexity that these savings afford, when taken together, is enormous.

In the next post we’ll look at Clojure’s approach to data, which is where uniformity really shines.

Safari Books Online has the content you need

Check out these Clojure books available from Safari Books Online:

Clojure Programming, helps you learn the fundamentals of Clojure with examples relating it to the languages you know already—whether you’re focused on data modeling, concurrency and parallelism, web programming, statistics and data analysis, and more.
Practical Clojure is the first definitive reference for the Clojure language, providing both an introduction to functional programming in general and a more specific introduction to Clojure’s features. This book demonstrates the use of the language through examples, including features such as STM and immutability, which may be new to programmers coming from other languages.
The Joy of Clojure goes beyond the syntax, and shows how to write fluent, idiomatic Clojure code. You will learn to approach programming challenges from a Functional perspective and master the Lisp techniques that make Clojure so elegant and efficient. This book will help you think about problems the “Clojure way,” and recognize when they simply need to change the way they program.

About the author

edmund Edmund Jackson (@edmundjackson) is an independent consultant in all things Clojure and Data Science. Edmund is a member of LambdaNext, a Clojure training and consulting group. Currently based in Cambridge, UK he is looking forward to moving to the US at the end of 2013.

Tags: Clojure, Cthulhu, Escher, Homoiconicity, lisps, Rich Hickey,

Comments are closed.