6 ms·
I'm pretty much totally ignorant about Clojure in practice. One part I love about Ruby is being able to drop into an irb/pry session nearly instantly or run the
by evilduck 14y ago
I'm pretty much totally ignorant about Clojure in practice. One part I love about Ruby is being able to drop into an irb/pry session nearly instantly or run the Rails console and test out code and ideas interactively and being able to quickly restart the dev server if configs change. JRuby has always been appealing to me but it's kind of annoying to use for development due to the JVM startup time. I used to do Java development full time and had the same annoyance with needing the compilation/restart step to see changes.
Does Clojure address this problem or are there workarounds (like Guard/Spork for testing in Rails)? Is there anything fundamentally different from JRuby that would alleviate the slow restarts, or am I simply thinking about the problem wrong?
- jballanc 14y agoThe Clojure community just recently put its full weight behind nREPL. You can run nREPL from Leiningen outside of a project directory, much like IRB. To be honest, I've never noticed the JVM startup time... But there is another way! Clojure inherits the concepts of SLIME/SWANK from the world of LISP. Essentially, since functions (not objects) are the top-level constructs in Clojure, you can redefine functions at any time while your program is running, and everything will "magically" start using the new definition. So, the typical way one develops in Clojure is to start a SWANK or nREPL server, then load their program files into this server. At that point, you can run any single function or if you're writing a web app, for example, you can run the function that starts the web server, hit a URL, edit a function, re-evaluate, reload the web site and immediately see the results. ClojureScript One is one example of how this can be taken advantage of. You can see a demo of it here: http://vimeo.com/35153207 http://vimeo.com/35153207
- habitue 14y ago"Essentially, since functions (not objects) are the top-level constructs in Clojure, you can redefine functions at any time while your program is running, and everything will "magically" start using the new definition. " This isn't exactly correct. It's not because clojure has first class functions that you get this behavior, but because clojure has late binding: http://en.wikipedia.org/wiki/Late_binding http://en.wikipedia.org/wiki/Late_binding
- jballanc 14y agoTrue, but Ruby also has late binding. Ruby also has open classes, so you could (in theory) do something very close to SLIME with Ruby. The problem is, Ruby also has singleton classes and singleton methods, so there's no guarantee that a change made in code and evaluated in the runtime will have the desired effect. Actually, Clojure has a similar problem with defonce, but in practice I've found that Clojure works much better with the SLIME development model than Ruby does.
- banister 14y agoJust curious but why does singleton classes/singleton methods in Ruby make it "so there's no guarantee that a change made in code and evaluated in the runtime will have the desired effect" ?
- jballanc 14y agoWell, a trivial example: class Foo def bar puts "Hello from Foo" end end a = Foo.new def a.bar puts "Hello from a special Foo" end Now, even if you change the definition of "bar" in Foo's class definition, "a" will still have it's own version. This might not seem like a big deal, but as you do more metaprogramming with Ruby, more examples like this pop up.
- wreckimnaked 14y agoI use Nailgun[1] with vimclojure[2] and lein-tarsier[3] to avoid the JVM startup pain. You'll end up with a JVM instance (server) running all time and the possibility to evaluate code from many different clients like REPLs and the editor itself. Changes to the code just need to be evaluated again to override the previous function definitions. It ends up being a really fast workflow. 1: http://www.martiansoftware.com/nailgun/ http://www.martiansoftware.com/nailgun/ 2: http://www.vim.org/scripts/script.php?script_id=2501 http://www.vim.org/scripts/script.php?script_id=2501 3: https://github.com/sattvik/lein-tarsier https://github.com/sattvik/lein-tarsier
- vdm 14y agoDrip[1] takes a new approach to solving the same problem as Nailgun. 1. https://github.com/flatland/drip https://github.com/flatland/drip
- wreckimnaked 14y agoSeems nice. The only problem of using it instead of Nailgun for the Clojure development workflow is that starting a new instance of the JVM would mean to re-evaluate all the code, and not only the modified definitions.