27

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?

Community
  • 1
  • 1
Ande Turner
  • 7,096
  • 19
  • 80
  • 107
  • 1
    I've never heard of it! But its Lisp! Hurray! Lisp is coming back! – Andre Bossard Oct 08 '08 at 09:43
  • I'm interested to know the answer to this too. I'd like to know more about Clojure. – Jason Baker Oct 08 '08 at 13:29
  • @Andre Bossard: it never left. But now regarding Clojure specifically it did definitely help Lisp become "mainstream". Several startups are using Clojure and there are believed to be at least tens of thousands of Clojure programmers: that language is simply kicking ass. Be careful with sarcasm next time: you never after how many years your needless sarcasm will end up looking silly. – Cedric Martin Oct 03 '12 at 01:22
  • @CedricMartin there was honestly 0% of sarcasm involved in my statement. So be careful with your assumptions ... (there is no sarcasm in this statement as well) – Andre Bossard Oct 04 '12 at 15:26

4 Answers4

14

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.

duffymo
  • 305,152
  • 44
  • 369
  • 561
Rick Minerich
  • 3,078
  • 19
  • 29
6

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:

http://blip.tv/file/812787

I documented my first 20 days with Clojure on my blog

http://loufranco.com/blog/files/category-20-days-of-clojure.html

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

Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • @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 Videos@blip and read a lot of blogs aswell as your own. I'm really wondering as to the viability of jumping ship completely. – Ande Turner Oct 08 '08 at 13:53
  • 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 Oct 08 '08 at 13:59
4

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 clojure@googlegroups.com mailinglist

Ande Turner
  • 7,096
  • 19
  • 80
  • 107
  • @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. – Ande Turner Oct 30 '08 at 07:27
2

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.

pmf
  • 7,619
  • 4
  • 47
  • 77