2 ms·
I've written a substantial prototype in Scala, which included half a dozen Neo4j-backed implementations of scala.collection traits. As for Clojure, I've only
by snprbob86 15y ago
I've written a substantial prototype in Scala, which included half a dozen Neo4j-backed implementations of scala.collection traits. As for Clojure, I've only really toyed with it, but I have written meaty code in several other Lisp dialects. So while I am by no means an expert in either, I'd say I'm qualified to be skeptical of your claims. Furthermore, I have no vested interest in either language. I have a future production project in mind for each of them.
I'm going to ignore the discussion about functional vs OOP, and team sweet spots, and cognitive load of the Scala type system, and all of that. I agree with and disagree with several of your points, but they are not relevant.
Scala, being a statically typed language, has some additional "ceremony" over a Clojure. That's for sure. But, in my experience, that ceremony is a relatively small fixed cost of around 5 to 10 lines per "big scary top-level thinggie" in the problem and solution domains.
In general, I'd expect the Clojure source code to be shorter by about 5%, not 75%. In some cases, either Scala or Clojure will be significantly shorter that the other, depending on whether or not the type system or macros are employed cleverly.
Regarding your specific claim -- "The form of the Clojure code mostly follows the form of the Scala code" -- I am beyond skeptical. I do not trust your account of "mostly the same functions".
Without seeing concrete examples of how the code shrank so significantly, your anecdote is not useful to any reader.
- seancorfield 15y agoThanx for taking the time to give some background. I posted the anecdote on the Clojure list just by way of sharing some of the progress we were making with Clojure. If someone had actually asked me, I'd have probably said "No, don't post this on HN" because it's an isolated anecdote - not a general case. A couple of folks have picked on the "Clojure code follows the Scala code" claim. Since the code embodies a fair bit of proprietary business logic, I can't share it - which is a shame because it would clearly show the structure really is very similar with almost all of the same function names. I'll see if I can find some time to sit down with the two code bases side by side and produce a more detailed comparison which would answer some of the more critical voices here. A couple of folks mentioned library support and part of the increased conciseness in the Clojure probably comes from that - in particular, in Clojure, a SQL query result is a sequence of maps whereas I had to construct a collection wrapper around ResultSet in Scala (remember, the code was written back 2009 - there are better SQL abstractions available for Scala now as third party libraries). Using parallel collections in Scala would more closely mirror the approach we now use in Clojure - and that would shrink the Scala code a bit - but parallel collections weren't available when the code was written. However, using agents in Clojure - which would more closely mirror the old Scala code - would only add a few lines. I think the Scala code could be made quite a bit more concise because of the advances in Scala over the last two years. I suspect I could make the Clojure code a little bit more concise too. I don't believe I could make the Scala code more concise than the Clojure code.