Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've been taking a look at Clojure lately and I stumbled upon this post on Stackoverflow that indicates some projects following best practices, and overall good Clojure code. I wanted to get my head around the language after reading some basic tutorials so I took a look at some "real-world" projects.

After looking at ClojureScript and Compojure (two the the aforementioned "good" projects), I just feel like Clojure is a joke. I don't understand why someone would pick Clojure over say, Ruby or Python, two languages that I love and have such a clean syntax and are very easy to pick up whereas Clojure uses so much parenthesis and symbols everywhere that it ruins the readability for me.

I think that Ruby and Python are beautiful, readable and elegant. They are easy to read even for someone who does not know the language inside out. However, Clojure is opaque to me and I feel like I must know every tiny detail about the language implementation in order to be able to understand any code.

So please, enlighten me!

  • What is so good about Clojure?
  • What is the absolute minimum that I should know about the language in order to appreciate it?
share|improve this question
7  
I don't understand why someone would pick Clojure over say, Ruby or Python - it runs on the jvm and can use the entire java library. ... have such a clean syntax arguably, lisp like functional languages have a very clean syntax and structure, its just one most people aren't used to. –  MichaelT Dec 11 '12 at 21:12
11  
Its name is sexy. –  Jason Holland Dec 11 '12 at 21:12
2  
@MichaelT Ruby and Python too have implementations that run on the JVM so this point is not compelling for me. –  marco-fiset Dec 11 '12 at 21:14
1  
@JasonHolland I think the name is cool too, but that is not enough to convince me ;) –  marco-fiset Dec 11 '12 at 21:17
2  
I started looking at Clojure recently (but I have prior experience with Haskell and Scala, so the syntax isn't such a shock). I actually found it surprisingly readable. There are very few symbols outside of parenthesis compared to many languages, and almost no reserved words. The reason you find it unreadable is because it's a totally new paradigm and works in a fundamentally different way than a typical Object Oriented language. Give it some time and power through. –  KChaloux Dec 12 '12 at 13:54
show 4 more comments

closed as not constructive by Robert Harvey, Walter, Thomas Owens Dec 12 '12 at 0:46

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers

up vote 10 down vote accepted

For the background you gave, if I may paraphrase:

  1. You're familiar with Ruby/Python.
  2. You don't see the advantages of Clojure yet.
  3. You don't find either Lisp or Clojure syntax clear.

...I think the best answer is to read the book Clojure Programming by Emerick, Carper and Grand. The book has numerous explicit code comparisons with Python, Ruby, and Java, and has text explanations addressing coders from those languages. Personally, I came to Clojure after building good-sized projects w/ Python, and having some Lisp experience; reading that book helped convince me to start using Clojure not just in side-projects but for professional ends.

To address your two questions directly:

  1. What's so good about Clojure? Plenty of answers on this site and elsewhere, e.g. see What's your reason to learn Clojure?
  2. What is the absolute minimum that I should know about the language in order to appreciate it? I'd suggest knowing the big ideas behind Clojure's design, as articulated in both Clojure Programming and The Joy of Clojure books-wise, and in Rich Hickey's talks, esp. the talk Simple Made Easy. Once you know the what/why you can then start understanding the how when reading Clojure code, esp. how to change your thinking from classes, objects, state/mutation to "just functions and data" (higher-order functions, maps/sets/sequences, types).

Additional suggestions: Lisp's elegance and power is partly from its minimalist and utterly consistent syntax. It's much easier to appreciate that with a good editor, e.g. Emacs with clojure-mode and ParEdit. As you get more familiar with it, the syntax fades away and you'll "see" semantics, intentions, and concise abstractions. Secondly, don't start by reading the source for ClojureScript or Compojure, those are too-much-at-once; try some 4clojure.org problems, and compare solutions with the top coders there. If you see 4-6 other solutions, invariably someone will have written a truly idiomatic, succinct FP-style solution which you can compare with a clumsy, verbose, and needlessly complicated imperative-style solution.

share|improve this answer
add comment

The strengths of Clojure have been highlighted many times, and, sure enough, make for a very powerful language, so I won't repeat them again here.

I always loved lisp, since the uni days and I was really excited when I discovered Clojure (perhaps the chance of using lisp outside of academia at last!). However as I started learning an uneasy feeling has begun to creep in, though I cannot pinpoint exactly what it is that I don't like. First of all I would say that coding in Common lisp was easy and fun for me but Clojure has a steeper learning curve. Clisp had a certain beauty and elegance to it. I'm not sure I'll get the same feeling from Clojure. I'm wondering if that feeling will go away as I get more experience.

I have another guess for my mysterious slight repulsion. I think it might be its great flexibility. For instance you can have structures that are half vector and half map and with a few characters of code you can accept them as parameters, take them apart and process them correctly. Yes, it removes all the boilerplate, but somehow it doesn't feel right. Is like you never know very well the rules under all those parenthesis, colons, brakets, etc are operating.

For me, I still love the language for all its advantages (primarily, running in the JVM and simplifying concurrency, while being much more powerful, and concise than Java and with less obvious design flaws) but the jury is still out as to whether something could have been improved.

share|improve this answer
add comment

Lisp dialects have a unique niche due to their simple syntax. This simple syntax makes meta programming through the use of macros very simple. This allows you to model the language to suit your problem domain instead of modeling to fit your problem domain into your language. It's really cool once you get your head around it, and it lets you do a lot of things easily that is very difficult in other languages.

The downside, is that since every Lisp program essentially defines its own language, you really need a solid grasp on things to understand what is going on.

Now, to answer your questions...

  1. Closure is a modern Lisp dialect that runs in the JVM/CLR. This makes it easy to take advantage of the power of Lisp in an existing infrastructure.

  2. It is essential to understand how to use macros to build Lisp to your problem domain to appreciate its usage. I really only understood this after implementing a Lisp runtime, when I found that much of the core language features can easily be implemented in Lisp itself. It takes a fair sized project to get this.

Now its pluses aside, although it is fun to program in, I personally don't have many cases where I would turn to it for daily problems. It is a very good tool to learn for mind expansion, and after learning Lisp properly, it became much more natural to take advantage of meta programming facilities in other languages.

The simple syntax makes it easy for computers to interpret (allowing such easy powerful macros), but it makes it very difficult for a human to parse complex expressions quickly.

share|improve this answer
2  
Have you looked at light table‌​? –  MichaelT Dec 11 '12 at 21:51
1  
Your answer makes it sound like macros are the normal way to approach Lisp programming, when in fact most programming problems can be solved with ordinary, first-class functions. Macros are intended primarily to be used for language programming (i.e. extending the language). See also bookshelf.jp/texi/onlisp/onlisp_9.html –  Robert Harvey Dec 11 '12 at 22:11
1  
@RobertHarvey I would argue that if you aren't taking advantage of marcos, then there are a plethora of other languages that I would turn to which offer first-class functions with a much more readable syntax. –  bunglestink Dec 11 '12 at 22:23
    
@MichaelT that looks neat. I like the concept. –  Jubbat Dec 11 '12 at 23:25
1  
@RobertHarvey Scala, JavaScript, C#, Python, and Haskell are all on the top of my head as far as languages with first class functions that I would consider more human-parsable syntax than Lisps. –  bunglestink Dec 12 '12 at 5:11
show 2 more comments

Not the answer you're looking for? Browse other questions tagged or ask your own question.