After discovering Clojure I have spent the last few days immersed in it.

What project types lend themselves to Java over Clojure, vice versa, and in combination?

What are examples of programs which you would have never attempted before Clojure?

+10  A: 

Clojure lends itself well to concurrent programming. It provides such wonderful tools for dealing with threading as Software Transactional Memory and mutable references.

As a demo for the Western Mass Developer's Group, Rich Hickey made an ant colony simulation in which each ant was its own thread and all of the variables were immutable. Even with a very large number of threads things worked great. This is not only because Rich is an amazing programmer, it's also because he didn't have to worry about locking while writing his code. You can check out his presentation on the ant colony here.

Rick Minerich
Great minds think alike :) Rick and I were both at the concurrency presentation Rich Hickey did in Northampton earlier this year.
Lou Franco
Does anyone know where to find the source for this ant colony demo?
Steven Devijver
Ant Colony Source:
Rick Minerich
+4  A: 

If you are going to try concurrent programming, then I think clojure is much better than what you get from Java out of the box. Take a look at this presentation to see why:

I documented my first 20 days with Clojure on my blog

I started with the SICP lectures and then built a parallel prime number sieve. I also played around with macros.

Lou Franco
@LouFranco: Oh hey, yeah I read all of your posts last night, didn't make the connection before, sorry. It was very informative, thanks. :) I've watched all the [email protected] and read a lot of blogs aswell as your own. I'm really wondering as to the viability of jumping ship completely.
The biggest issue for me is interpreting error messages from the compiler. It gets easier over time. I don't have a project right now that I want to run on the JVM, but if I did -- it'd be in Clojure.
Lou Franco
+4  A: 

What project types lend themselves to using Java over Clojure, vice versa, or in combination?

A project where a GUI-building tool (such as Matisse in Netbeans) is needed would be a case where Java may still be required. Anything done in Java can be done in Clojure quite readily, with proxy and gen-class if needed, or just accessing Java as needed (., doto, new, etc.). This allows Clojure projects to easily use Java libraries or legacy Java code.

Which programs which you would have never attempted before Clojure ?

Before I found Clojure, I was contemplating a project that required JDBC, would run in a servlet container, and I anticipated doing a lot of iterative development because it wasn't clear what methods would work for the data I needed to analyze. I put it on the back burner because I didn't have the time or patience for the compile-debug- deploy-validation cycling that Java requires. I've now written the application in Clojure, and I'm very pleased at the ease of making changes on the fly and being able to examine the results immediately. Not to mention the joy of lock-free programming and being liberated from having to develop (and refactor) class hierarchies.

- "MikeM" via the [email protected] mailinglist

Did you use any framework for making a Clojure servlet?
J. Pablo Fernández
@J.PabloFernández: I would suggest you head over to the Clojure group @ Google Groups and ask your Question. There are plenty of experienced users along with the creator of Clojure Rich Hickey.
+1  A: 

What project types lend themselves to Java over Clojure, vice versa, and in combination?

If you want to develop a framework that is to be consumed by Java and Clojure, I've found writing the main abstractions (interfaces ad base classes) in Java to be preferable over writing them in Clojure (I find Clojure's gen-class to be somewhat tedious and rather use proxy).

If you're a user of Hibernate or any other framework that makes heavy use of Java-annotations without offering a programmatic alternative, you'll have some trouble, since it's not trivial to emulate annotated POJOs with Clojure's data structures.

Apart from that, I've experienced no use cases for which Clojure is less appropriate than Java; you have to cope with the loss of static typing, of course, which feels somewhat disconcerting at first, but tends to go away.