Hacker News new | ask | show | jobs
by tomp 4427 days ago
> With Clojure your editor (be it Vim, Emacs, Light Table...) is permanently connected to a live REPL. You continually develop, test and modify functions with subsecond feedback. Continuously.

Can anyone explain or point me in a direction where I can learn how the above functionality is actually used and useful?

I keep hearing about live-editing/hot-reloading, and in theory I believe it must be very useful, but I cannot concretely imagine how it would be used in practice. What kind of programs can work like that? Continuously running programs, like web servers/GUI programs? So what happens when you change a function? Do you manually simulate a web-request? Rerun unit tests? Would it work with command-based pipelined programs, such as compilers as well?

4 comments

It's a side effect of decoupling. If you don't need to pass the world in to a function, then it is much easier to poke at.

I played with Clojure making a simple pong game, and used this to work on collision detection. I worked on a function called rect-intersects that took in two rectangles. It was much faster to work on than if I'd booted up the game each time.

The beauty of Clojure (and all functional languages) is that everything your app does is made of very small functions composed together. You wouldn't really simulate the round trip http request via the REPL but you can change and test idempotent functions independent of each other. Most Clojure functions are under 15 lines of code.

You can also mess around with transforming state that you may have stored in an atom...

> What kind of programs can work like that? Continuously running programs, like web servers/GUI programs?

I use Common Lisp and Hunchentoot to build RESTful web applications. I can connect to the Lisp image running on the server using Swank from Emacs on my development box. If there is a bug, I can change the function, recompile it, and test the change with curl, without rebooting the server or reloading the app. The same techniques work for adding new functionality and APIs.

I suggest just giving it a try. It'll change the way you think about building systems.

What do you do then, after successfully fixing the bug? Are the changes automatically reflected in files, or do you need to manually perform the same change locally and commit it, so that it's there when the server is next redeployed?
If you check out our meetup [1], we do Google Hangouts based demos of this in emacs as part of our SICP study group. It's all free and we are happy to help in person if you are in the Philly area.

[1] http://www.meetup.com/Clojadelphia/