Picture of stu

The Case for Clojure

  • Posted By Stuart Halloway on October 19, 2009
  • Tags

The case for Clojure is richly detailed and well-documented. But sometimes you just want the elevator pitch. OK, but I hope your building has four elevators:

  • "Concurrency is not the problem! State is the problem. Clojure's sweet spot is any application that has state."
  • "Don't burn your legacy code! Clojure is a better Java than Java."
  • "Imperative programming and gratuitous complexity go hand in hand. Write functional Clojure and get shit done."
  • "Design Patterns are a disease, and Clojure is the cure."

Any one of these ideas would justify giving Clojure a serious look. The four together are a perfect storm. Over the next few months I will be touring the United States and Europe to expand on each of these themes:

  • "Clojure's sweet spot is any application that has state." At Oredev, I will be speaking on Clojure and Clojure concurrency. I will demonstrate how Clojure's functional style simplifies code, and how mere mortals can use Clojure's elegant concurrency support.
  • "Clojure is a better Java than Java." I will be speaking on Clojure and other Java.next languages at NFJS in Atlanta and Reston.
  • "Design Patterns are a disease, and Clojure is the cure." I will sing a siren song of Clojure to my Ruby brethren at RubyConf.
  • "Write functional Clojure and get shit done." At QCon, I will give an experience report on Clojure in commercial development. Our results so far: green across the board. Both Relevance and our clients have been pleased with Clojure.

Want to learn about all four of these ideas, and more? Early in 2010, I will be co-teaching the Pragmatic Studio: Clojure with some fellow named Rich Hickey.

If you can't make it to any of the events listed above, at least you can follow along with the slides and code. All of my Clojure slides are Creative-Commons licensed, and you can follow their development on Github. Likewise, all the sample code is released under open-source licenses, including

And remember: think globally, but act only through the unified update model.

Comments
  1. Paul BarryOctober 19, 2009 @ 07:48 PM

    When you say state, do you mean state that is stored in memory and accessible by multiple threads? If that is what you have, then Clojure is a good choice. But also by that definition, most web applications don’t have state. State is usually stored in an external mechanism like a SQL database. Any in memory state is thread-local, only seen by one thread as it responds to one HTTP request, therefore Clojure’s state stuff isn’t any benefit in that case.

    Do you agree, or are there cases where a web application has state that Clojure can help you deal with?

  2. S. DatskovskiyOctober 19, 2009 @ 09:42 PM

    I invite everyone to consider the case against Clojure: http://www.loper-os.org/?p=42

    Sure, you get a shiny, exciting toy to play with now. However, peacefully compromising with bad engineering has consequences. Software will reach a state of Idiocracy within our lifetimes.

  3. Evan LightOctober 19, 2009 @ 10:40 PM

    Stu,

    I’m curious: Are you finding that you’re consistently choosing Clojure over Ruby just as, until fairly recently, you were choosing Ruby over Java?

    Put another way: do you find that you and your team (Relevance) are more productive delivery web applications in Clojure than in Ruby?

  4. vsyncOctober 19, 2009 @ 11:58 PM

    I have been following Clojure with some interest lately. I’m still a Common Lisp guy though because Clojure is still in flux and evolving rapidly from what I see.

    I also see the fact that all Clojure programs are Java programs as a plus and a minus: a plus because you get access to all the Java libraries and JITs and whatnot out there, but a minus because there can’t be any independent Clojure port. In the real world to make an interesting port of Clojure you will also have to port all of Java so applications work. It’s like if no one wrote Unix/Linux applications but only Windows and counted on Wine always being there.

    With regard to state - and Paul Barry already touched on this - I recently started implementing a small app which needs some persistent state. I thought to try doing it in Clojure but found out that while Common Lisp has tools like Rucksack and Elephant and CLSQL, if I wanted it in Clojure I would need first to create all my data structures as Java objects (albeit with (. blahblah) wrappers if I wanted) then run them through some clumsy Java ORM, or deal with raw JDBC or Java Berkeley DB.

    If I missed something that’s already out there and available I would love to be pointed to it, but it seems to me Clojure could benefit from a native persistence mechanism or library that takes advantage of its concurrency strengths, or at least a native API for something like Berkeley DB that can deal well with it.

  5. VaCoderOctober 20, 2009 @ 01:43 AM

    I think Clojure is a tougher sell to Java folks than Ruby or Groovy was. For average coders like me, the syntax takes some getting used to and the concepts take time to sink in.

  6. LisperOctober 20, 2009 @ 04:32 AM

    @ Stan Datskovskiv

    I’m not sure how that contributes to the discussion at hand. Clojure was written and designed as a modern LISP. We wouldn’t say “bad” engineering in LISP was why Clojure was started but rather the old LISP was outdated and failed to include new and better ideas that have been discovered since CL was standardized (concurrency, multi-core, the sequence abstraction, etc). Yes, engineering does involve making hard choices and tough compromises, but for many, Clojure made the right ones.

  7. AnonOctober 20, 2009 @ 05:14 PM

    @vsync

    Look at the current efforts to write Clojure in Clojure. Also, see the CLR effort.

  8. HaroldOctober 20, 2009 @ 09:10 PM

    I’ll believe more in these new languages when they are promoted by people who don’t make a living out of them, such as consultants.

  9. Stuart HallowayOctober 21, 2009 @ 03:34 AM

    @StanDatskovskiv: Thanks, that’s helpful. I just called all my clients and told them we are suspending development until the Hurd kernel is completed.

    @Paul: The irony about state is that functional languages (which superficially avoid it) are better at state than imperative languages. Most web apps I have seen are filled with accidental in-memory state that Clojure can eliminate.

    @vsync: there are lots of Clojure persistent APIs. I have been playing around with redis-clojure and it rocks. There is clj-record for people familiar with ActiveRecord, and ClojureQL for getting to SQL in a Lispy way.

    @VaCoder: You are right, there is more new stuff to learn (for a Java programmer) in Clojure than in Ruby or Groovy. I spent three years doing primarily Ruby before making the switch.

    @Evan: I am more effective in Clojure than in Ruby, but the Rails ecosystem is more than just a language. There are some web apps that are easier in a Clojure web framework, others that are easier in a Ruby web framework. Clojure is gaining ground all the time.

  10. RossOctober 21, 2009 @ 06:09 PM

    Speaking of Clojure, the example in P1.0 p172 doesn’t seem to work.

    user=> (def foo 10)
    #'user/foo
    user=> (binding [foo 42] foo)
    10
    user=>
  11. Brian CooleyOctober 22, 2009 @ 01:05 AM

    @Ross: Weird, it works for me.

    user> (def foo 10)
    #'user/foo
    user> (binding [foo 42] foo)
    42
    
  12. RossOctober 22, 2009 @ 04:42 PM

    I think I’ve resolved this, my recent d/l (1.1.0-alpha-SNAPSHOT) seems to have been withdrawn, or I just picked TWT, in any case today the featured d/l is Clojure 1.0.0- and it works…

  13. kunjan kshetriOctober 24, 2009 @ 09:26 PM

    Stu, I love the langugage and thank you for doing so much for it. And Thanks a ton for providing slides. I hope the conference allows you to release other multimedia too.