6 ms·
I 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
by rjd 15y ago
I 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 think you're striving for absolutes where only relatives exist. You're right that I said 3-4x in one place and 2-3x in another. Sorry. It's a gut feeling. Is it 2x, 3x, 4x? One of those. Any of those depending on the code. Somewhere in the middle. It's going to depend on the specific code. You can't reasonably suggest that language X is always Nx more concise than language Y, surely? So, somewhere in that space, Scala is a substantially more concise than Java (will you allow "substantially"?) and Clojure seems to be substantially more concise than Scala. Is that suitably vague for you? :)
- Uchikoma 15y agoA little bit disappointed about the down votes, I'd hope we as an industry take numbers not so lightly and find "Is it 2x, 3x, 4x? One of those." no longer comfy. I'd also hope we strive more towards "Extraordinary claims require extraordinary evidence" and more science than folklore.
- rjd 15y agoAwesome thank you so much for reply, its high appreciated :) I'd blame my misspelling on OSX's new autocorrection feature, but I suspect it was me as I pronounce it closure :O
- darklajid 15y agohttps://secure.wikimedia.org/wikipedia/en/wiki/Clojure https://secure.wikimedia.org/wikipedia/en/wiki/Clojure > Clojure (pronounced "closure"[2]) is a recent dialect of the Lisp programming language created by Rich Hickey. So - you're good regarding the pronunciation :)
- Dn_Ab 15y agoI think it would be very instructive to some of us in the sidelines. It looks like you used the same idioms? Why do you think, what is it about clojure that allowed you to expresses the same thing in less code?
- hxa7241 15y agoI have a comparison too: a rather different kind, but no less reasonable for this sort of game, and with all source available -- http://www.hxa.name/minilight/#comparison http://www.hxa.name/minilight/#comparison It says that languages do not vary by factors of 10. Considered as pure 'lexical structure' the range is about 2 or 3 between small and large. Anything more than that must have some reason -- most probably library support. Of course, library support is important, and quite fair to be compared in lines -- it represents real work that has to be done. But it seems worth trying to distinguish it as a library matter -- or whatever else.
- rayiner 15y agoTwo very different examples. Simple, math-heavy things tend to be best-case scenarios for verbose languages.