English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Developing a Clojure Edge

1. The Clojure Edge

As a programmer I have had the pleasure of working on many interesting projects, in various languages, but always with a nagging feeling that there must be a more expressive way to do my work.  A language that would augment my ideas, would allow me to represent algorithms and data clearly without frameworks and boilerplate.  A language that would make me a coding ninja, churning out solutions instead of infinitely fixing some monolithic contraption held together by duct tape.  Clojure is that language, the language of code ninjas.  You will be more productive.  You will think about problems more precisely, and solve them more elegantly.

General housecleaning: The opening paragraph of each chapter needs to start by summing up what was accomplished in the previous chapter, then capturing the high points of what will be covered in this chapter. Then at the end of the chapter we need a summary that explains briefly what the reader has learned by completing the chapter and then mentioning what is coming up in the next chapter. -TM


Clojure is a practical, general purpose, functional programming language that embraces its host platform, the Java Virtual Machine.  Being a lisp with homo-iconic syntax, code is data and manipulated through macros to yield terse but meaningful abstractions.  Clojure is a dynamic language for interactive development with optional type hints and type inference.  It is designed for concurrency, providing fast persistent data structures, and offers a software transactional memory system to deal with mutable state.  Clojure is a fresh language that builds upon time proven principles and ties together a coherent and productive environment for development, supported by a vibrant community.


Clojure requires thinking.  Some people value frameworks and constraints over creativity and expressiveness.  But you cannot be a great programmer without thinking, and you will only reach your true potential expressing code in ways that empower you rather than constrain you.  Frameworks and constraints provide the most value when you know what you are trading for them, and when that makes sense.  I guarantee that learning Clojure will change the way you think about how other languages and frameworks work best.

Great start, I look forward to reading the completed chapter. TM


Why learn Clojure?


Clojure is an important language because it is fast.  Code can run as fast as its host platform.  Clojure is ubiquitous.  It can target the JVM, .NET and javascript.


Clojure is an aesthetic and practical language which has many qualities that you will be interested in.  I will point these out upfront and refer to them as we encounter them in a practical context.  To facilitate this I will use an acronym PRECISE.


Predictable


Functions and data.


Deterministically understanding what has and will occur, based upon the outcomes of causality. Every action, or cause, produces a reaction, or effect, and every reaction, in turn, becomes the cause of subsequent reactions. The totality of these cascading events can show exactly how the system will exist at any moment in time.


Reason enabling


Referential transparency allows the programmer and the compiler to reason about program behavior. This can help the programmer in proving correctness, simplifying an algorithm, modifying code without breaking it. The compiler can optimize code by means of memoization, common subexpression elimination or parallelization.

Freedom from a defined order of evaluation is good for expression, reasoning


Ecosystem enabled


Leiningen is an excellent build automation and dependency management tool for the simple configuration of software projects.  It is a real pleasure to use.  Clojars hosts a wide and well maintained community of libraries.


Interop provides convenient access to every Java library out there.  Many popular libraries


Composition friendly


Prefer composition over inheritance


Interactive


Cut out the compile run test

Quickly test interfaces or ideas

Save repl as test cases

More fun


Simple


Modular

Do one thing well

Not intertwined


Expressive


Philip Wadler of Bell Labs coined the term Expression Problem in an unpublished paper that he circulated by email in 1998 (http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt). "The Expression Problem is a new name for an old problem. The goal is to define a datatype by cases, where one can add new cases to the datatype and new functions over the datatype, without recompiling existing code, and while retaining static type safety (e.g., no casts)."


Datatypes

Protocols

Multimethods

Clojure favors uniform interfaces, so it encourages storing structured data in maps

Terseness

DRY


Key ideas


  • Embrace an industry-standard, open platform.

  • Modernizing Lisp

  • Functional programming with immutable persistent data structures

  • Built-in concurrency support.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.