What do you all think of Clojure's "REPL-driven development" method?

Using the REPL is one thing (I do it a lot in elixir), but quite another thing is clojure people saying that slow compile times are not a problem, because REPL driven development with whatever tooling they prefer (loading individual modules or functions, or whatever) is the ultimate workflow and just so much better than actually compiling the whole project.

Clojure compile times ARE slow, and Clojure REPLs generally don’t use ahead of time compilation, so they recompile everything when they start. So starting a REPL on a big project can take minutes. This is definitely part of why REPL driven development is popular - only reload code that has changed - never stop your REPL unless dependencies need to be reloaded or something has gone very wrong. Having said that, however, it IS very useful to have your system constantly running as you are building it. This is very different from simply having a REPL up that you can try things out in (like Swift’s playgrounds).

REPL-driven has its perks too, like take LISP, it has no real startup time at all but it still rules there too. It is really more about the ‘state’ of the program being serializable and changeable.

1 Like

I know that this discussion is pretty old, but I’d like to chime in anyway. I’ve basically just started looking into Elixir and the biggest part of my programming background is tainted by Python. But I’m also familiar with the Clojure way of doing things. One thing that I was always a bit jealous of was the REPL driven development that you could do in Clojure. While you can do a lot of things on the REPL in Python, loading a whole project with state and many classes is not something that is really possible. In the end Python is not an FP language. Once too many moving parts are involved, it get cumbersome. So most of the people do what I call pdb driven development. You run the code up to the break point and do your explorations there. When I read the comments here I though “okay, it’s similar in Elixir”. But that’s actually not true and you don’t explicitly mention it here.
So for all of the newcomers that are interested in REPL driven development: It’s working. Just not like in Clojure. In Clojure you send parts of the code from the editor the the REPL. That’s not what’s happening here. With an Elixir project you just edit your code, switch to the REPL and invoke recompile(). Now the whole code gets recompiled and you can proceed with your explorations. Also your previous state is still there. If you’ve loaded some JSON into a variable, then you can still use it. I’m really impressed by this and I think I like it even more than what Clojure is doing.

PS: Please correct me if I’m saying anything wrong. At least for my little test projects this worked so far.

6 Likes

Seems to be a lot of inaccuracies about Clojure in this thread. Clojure compile times are really fast, and not slow at all. Applications written in Clojure may have slow startup times, and maybe this is the confusion people had here?

REPL-driven-development in Clojure does not mean working at the REPL, it means working at the editor, and synchronizing the code in your editor with a running REPL, often time with the state maintained if you want, or not if you don’t want or maintaining some of the state and not other parts of it.

This also means incremental compilation, where you can re-compile part of the code only and hot-swap it in the running REPL where existing dependent code automatically starts using the newly loaded one.

As interactive development goes, Elixir is pretty damn good compared to most other languages, sex gives you a lot of power, but I’d say it’s still not quite REPL-driven-development. There’s a bit more back/forth with iex, but you kind of end up adopting a different workflow which some people might prefer, which is closer to TDD I’d say, as opposed to RDD.

2 Likes

I think clojure’s REPL needs a lot of development, it lacks basic functionality.

Could you expand? There isn’t a single Clojure REPL, but many of them, some with way more features than others. What specific feature you found lacking, maybe I can point you to a REPL that has it, or maybe you’re right and it is still lacking, it’s definitely not like it couldn’t be further expanded on.

Yeah, It can be expanded. I don’t know much about clojure’s repl as I am new to functional Programming and to LISP in general. I was talking about the REPL which comes with default installation on Linux. I have installed clojure by following the steps in official docs.
Please suggest me some alternative REPLs.

Ah yes, the default REPL is quite basic.

You would want to be using nRepl with the Cider Middleware and generally interact with it using either Calva (a VSCode plugin) or Cider (an Emacs plugin).

Though there are others that offer good features as well, but this is the most common setup for a powerful REPL development experience.

But for example, with those REPL you can have things like:

Code highlight, syntax formatting, inline evaluation, command history, documentation as you type, auto-complete, debugging with breakpoints, locals inspection, multiline support, jump to definitions, macroexpansion, source lookup, execution tracing, pretty printing, support for displaying images, advance text editing, refactorings, etc.

See:

If you’re curious, the n in nRepl is for network, its a REPL for Clojure that allows remote connections over the network and thus run as a server. This allows better text editors to connect to it, since with a terminal you’re quite limited in the text editing department. Thus with nRepl you can have both powerful REPL and good text editing in a real editor.

If you’re wanting something that is a powerful REPL but still meant to be used from a Terminal, you’d want to use rebel-readline:

Which implements a much better Terminal readline than the default Linux one (gnu-readline). And thus it gives you colored highlights, multiline, inline documentation, auto-complete, history, and other things directly in the terminal.

See this for a demo of it: Quick Demo of soon to be released readline library for Clojure/Script - asciinema

2 Likes