I constructed a subsystem in Clojure. We had a nice, compact problem to solve. The rest of our app talks to this Clojure bit through a small interface. The attraction of Clojure was that I could enjoy all the nimbleness of hacking Lisp interactively. Using such a powerful language, I could adapt to emerging requirements, experiment, twiddle, and workaround faster than using Java. And early on, that largely proved true.
But I am here to tell you: It is possible to write inflexible, unmaintainable, fragile code in Clojure.
As they say in bicycle racing, the riders make the race. I never said I was a good programmer.
It's my own fault. I dived into Clojure and learned key concepts on the run. And these key concepts are fundamental to how you should structure your program. FP has a learning curve. Managing shared state using Refs, Agents and STM -- better to understand these concepts up front. Even now, I'm unsure how I'd restructure my code to use them properly. I'm very glad not to have to worry about deadlocks. But there are parts of this code I still am unsure how to to test for consistency under multithread access.
Consequently, I'm slogging through this bowl of spaghetti of my own making, cursing the author.
[Edited to add "fragile" ... as I made one more change and my tests came tumbling down... ]
Hugh Winkler holding forth on computing and the Web
Showing posts with label clojure. Show all posts
Showing posts with label clojure. Show all posts
Thursday, July 16, 2009
Saturday, January 03, 2009
Clojure vs JavaFX Script: only 5x slower!
Chris Oliver compares his JavaFX script to JRuby and Groovy and finds JavaFX 25 times faster.
I failed to get JavaFX compiler running on my Ubuntu, but I easily ran Chris's JRuby 1.1.6 test; so for calibration, my laptop comes in at 3:52, vs 4:22 on Chris's machine. Presumably we can scale results on my machine by 1.13.
Here's my Clojure version of the test:
It runs in about 50 seconds, or 56 after normalizing to Chris' machine speed. This puts Clojure north of JRuby and Groovy, but still 5 times slower than JavaFX.
If you remove the type hints, it runs in 4 minutes, or about the same time as JRuby -- and about 4 or 5 times slower than with type hints.
I failed to get JavaFX compiler running on my Ubuntu, but I easily ran Chris's JRuby 1.1.6 test; so for calibration, my laptop comes in at 3:52, vs 4:22 on Chris's machine. Presumably we can scale results on my machine by 1.13.
Here's my Clojure version of the test:
(defn tak [#^Integer x #^Integer y #^Integer z]
(if (>= y x)
z
(recur (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(dotimes [n 1000] (tak 24 16 8))
It runs in about 50 seconds, or 56 after normalizing to Chris' machine speed. This puts Clojure north of JRuby and Groovy, but still 5 times slower than JavaFX.
If you remove the type hints, it runs in 4 minutes, or about the same time as JRuby -- and about 4 or 5 times slower than with type hints.
Thursday, January 01, 2009
Clojure uptick
Needing to build a standalone piece of server software as an add on to our Java product, I seized the opportunity to see how far Clojure has come. Getting my dev system set up, and learning the language, I noticed the results Google was returning for my queries were mostly very recent... and lots from just last month.

Could Clojure be approaching critical mass?
I've only written a hundred lines or so of code, but here are some random things I love:
1. Shorthand for maps:
2.
3. Shorthand to select a value from a map: the map is like a function name
4. Shorthand for lambdas: #(...code...)
5. Shorthand for generating temporary symbols in macros:
4. No looping required -- use
5. Java libraries are easy to use.
I haven't yet fiddled with modifying state.
It's free, it's functional, it's got a hardened standard library, it's got a REPL. You can write a program and deliver it on any platform. What could hold it back?
Could Clojure be approaching critical mass?
I've only written a hundred lines or so of code, but here are some random things I love:
1. Shorthand for maps:
{:a 1 :b 3}.2.
sorted-map and hash-map -- thanks for letting me choose. Same shorthand syntax for either.3. Shorthand to select a value from a map: the map is like a function name
(my-map :a).4. Shorthand for lambdas: #(...code...)
5. Shorthand for generating temporary symbols in macros:
my-var#. No need to call (gensym).4. No looping required -- use
recur.5. Java libraries are easy to use.
I haven't yet fiddled with modifying state.
It's free, it's functional, it's got a hardened standard library, it's got a REPL. You can write a program and deliver it on any platform. What could hold it back?
Subscribe to:
Posts (Atom)