tags:

views:

871

answers:

3

I've been using Clojure for a little while and want to create some projects that are bigger and more complicated than toys. I've been using Java for the past few years and have become accustomed to what IDEs do for me -- compile lots of classes, package them up in jars, create batch files for users to start them with.

When I look at examples of development in Clojure they seem to be along the lines of load files into the REPL, see how they work, edit the file, reload, repeat. Nary a class or jar being generated anywhere. In Stuart Halloway's terrific "Programming Clojure" I couldn't find a single example of ":gen-class", for example. The Clojure IDEs that I have used (ClojureBox and the enclojure NetBeans plugin) seem to promote that same work flow.

Is this intentional? Are the tools too immature or do I just not "get it"?

I'd like to hear some work flow examples from folks who have created some non-trivial programs to be used by regular users (not other devs) if possible.

Thanks for sharing your opinions.

+5  A: 

The REPL development approach has been encouraged by most LISP family (and other functional language) IDE's for a long time. Some of these REPL's also feature the auto-complete features you might associate with a Java IDE.

REPL gives you a couple major advantages over the standard approach. The first is that it allows you to execute arbitrary code during the run-time of your program, which can make debugging multi-threaded systems much simpler. Second, and more importantly, it makes it easy to test your functions while you code. You don't need to build a framework around a new function or class, you can play with it directly in the REPL, and see how it responds to a variety of use cases.

tsellon
+3  A: 

I think there are really 2 questions here:

A) how to deploy (and build and manage dependencies). All I can say to that is look at other projects with similar goals/domains and copy them.

B) Workflow:

My work-flow is like this:

  1. open a file and write some high level wishful thinking declarations

  2. start writing some functions to support it

2.5 copy the function definitions to REPL as I create them

  1. open another file and write some basic tests to check the function works

3.5 copy these to the REPL

  1. iterate between the two buffers building the tests up to an example and the program toward an end goal. These eventually become similar activities and I know I’m done.

  2. wrap the secondary file up in deftest

Now when I come back in a month, I can just run my tests and be happy! Saving your REPL buffers can provide some value with little effort. That’s just what works for me at present, and I’m happy to be educated to better approaches.

As for selection of IDE vs REPL - most IDEs have plugins which have REPLs so I'm not sure its a one or the other choice - really its just about which text editor you are productive in, and how you want to manage your project structure. There aren't any 'do it this way' structures pre-made AFAIK so at this point it is easier to look at specific projects (like Clojure itself, or penumbra or compojure or any of the libraries listed on the main site.

Timothy Pratley
+4  A: 

Well, to start off, virtually any decent development plugin for any editor or IDE will give you a way to use the Clojure REPL from within the IDE. Probably even allow you to load files into the REPL for testing and such. You don't need to choose one or the other.

Enclojure is going a long way, that is for sure. However, most people are perfectly happy with using Emacs, including myself. Emacs uses a Lisp as its configuration language, so it's usually the most natural choice to a Lisper.

For languages that have REPLs, using the REPL as a major part of the development process is the norm. Editing files, loading them into the REPL, playing with them to see if a work, rinse, repeat. This is one of the major advantages of languages with REPLs like Clojure and Haskell and CL and such.

As for building jars, and compiling Clojure code and stuff, that's simple. You don't even really /have/ to Compile Clojure code most of the time if you don't want to. When you do, you AOT compile it with gen-class, which compiles it to class files that you can then put into a jar. There are tons of examples and even tutorials spread amongst the interwebs. The easiest and most efficient way is to use something like Ant and writing a build script that compiles Clojure code and generates the .jar for you. The first time I did it, I thought it was going to be hard to do, but it was actually really simple. I just looked at the Clojure and Clojure-Contrib Ant build files, and referenced the Ant help pages for everything else I needed.

One thing I should mention is the fact that Enclojure /does/ actually build executable .jar files for you, if you request it to do so. I'm sure more advanced things you're used to will be added in the future. They are, indeed, still quite new.

Rayne