6 ms·
I'm not so sure this is a Clojure vs Scala story, as much as it is a Write One To Throw Away story. "The form of the Clojure code mostly follows the form of th
by snprbob86 15y ago
I'm not so sure this is a Clojure vs Scala story, as much as it is a Write One To Throw Away story.
"The form of the Clojure code mostly follows the form of the Scala code, most of the same functions"
Well evidently not. Otherwise, the code would not have seen a 75% reduction in lines of code.
What specific transformations resulted in this delta?
- rjd 15y agoI was a little disappointed in the point where he said he rewrote it in 15 hours, and was 75% lighter code... and didn't explain why. Makes me think is think a few things... - the original code was bloated and needed a rewrite anyway, and hence was performing badly. Most importantly having written lots of code that has evolved myself over the years... I have taken my own code (written in the same language) and cleaned them unto be half the size of they where before hand. - The closure rewrite was incomplete as compared to the scala version and totally invalidates his comparison - would the out of memory issue and performance difference be solved by not using actors with known memory leaks and swapping to akka. Would love a follow up on this as I'm slowly learning scala as a hobby ATM
- seancorfield 15y agoIt's Clojure, not "closure". Yes, switching to Akka would almost certainly have solved the OoM problems. That's the whole point. We had to switch from the original code. The choices were: move to Akka, wait for 2.10 (when Akka replaces the default actors implementation - and whatever migration was involved), or rewrite. Given that we're getting heavily into Clojure, it seemed a worthwhile spike to create a Clojure version to see how it performed... Was the original code bloated? I don't think so. I've written a LOT of code over 30+ years in dozens of languages. When the Scala code was written two years ago I was very impressed with its conciseness compared to Java (and other languages). My experience has been that Scala is 3-4x more concise than Java in general (and sometimes as much as 10x more concise) but Clojure is even more concise. If you're learning Scala, don't let this put you off: Scala is an incredibly impressive language. Odersky and his team have done an amazing job.
- Uchikoma 15y agoI wonder a little about your numbers. Scala is up to "10x more concise" as Java - your numbers suggest as they represent more or less the same structure in Scala and Clojure - a 4x reduction from Scala to Clojure (260 loc vs. 1000 loc). This would result in a 12x (4x3) to (4x10) 40x reduction from Java to Clojure. Which is hard to believe. Take this example where [edit] Python is compared to Java with a 1.7x size reduction: http://codemonkeyism.com/comparing-java-and-python-is-java-10x-more-verbose-than-python-loc-a-modest-empiric-approach/ http://codemonkeyism.com/comparing-java-and-python-is-java-1... Could you give an example to reduce this code by 12x, or even by 40x? The biggest reduction LOC would probably be the reduction in constructor size with Scala case clases.
- seancorfield 15y agoYour math is a bit off: Scala can be _up to_ 10x more concise than Java. This specific Clojure code was either 3x or 4x more concise than this specific piece of Scala code (based on char count or line count). My experience over the last few years suggests that Scala code can be anything from 2-3x to 10x more concise than Java. My experience also suggests that Clojure code can easily be up to 10x more concise than Java. I don't think too many people would argue with that as a general rule (or at least, not too many people who've programmed in all three languages :) I'll take a look at the link you posted and respond in more detail later.
- Uchikoma 15y agoCould you elaborate on the point where my math is off? You mentioned a range from 3-10x between Scala and Java, and we have a 4x multiplier with your code (260 LOC Clojure vs. 1000 LOC Scala). This would result in a 12 - 40x range which I quoted in my comment. I also find it a little discomforting that "Scala is 3-4x more concise than Java in general" becomes "my experience over the last few years suggests that Scala code can be anything from 2-3x" in a matter of minutes. You're sure about your numbers? Not wanting to be offensive, but it sounds a little like you pull them out of thin air.
- seancorfield 15y agoI'd have to ask how much Scala and how much Clojure you know to challenge my statement about the equivalence of the code and the reduction in size? (no offence intended - a genuine question) I like Scala. I'd hoped it would become my company's "One True Language". It has a lot less ceremony than Java. I went thru the very painful 2.7 to 2.8 transition. I attended Scala Lift Off! 2010 and Scala Days 2011. I think Scala is very impressive - a (much) better Java. I hope it will succeed and I still follow it closely. I've always liked functional programming, and Lisp, and Clojure hits a particular sweet spot for me. It also happens to hit a sweet spot for our company - our developers like dynamic scripting languages and Clojure fits that better than Scala. Scala _allows_ you to adopt a functional style but doesn't enforce it (and, to be honest, makes you work at it) - Clojure makes you work at deviating from the functional path. Clojure has less ceremony than Scala, is more functional (or at least more purely functional), and - in my opinion - far fewer demands on developers in terms of what you must learn to be productive...
- snprbob86 15y agoI'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.