On Performance and Java Interoperability: Clojure vs. Scala

前端 未结 8 687
滥情空心
滥情空心 2021-01-30 01:47

I have already read various accounts of Clojure vs. Scala and while I realize that both have their place. There are a few considerations that I haven\'t acquired a complete exp

8条回答
  •  无人共我
    2021-01-30 01:55

    1. Idiomatic Scala is faster than idiomatic Clojure, and will remain so.
    2. Both Scala and Clojure sit easily on top of Java. Neither sits well underneath it.

    If your code is time-critical or space-critical throughout, stick to Java. But it isn't, even if you think it is.

    The Computer Language Benchmark Game sheds little light on Clojure's true resource costs. No Clojure data structures are employed. Functional and sequence abstractions do not appear.

    Clojure may appear to be simple. It isn't, but it is expressive. It may run five times slower than Java, but the source is five times smaller (YMMV). For most of most applications, this is a big win. But for some, and for some parts of many others, it's a devastating loss.

    With experience of the Clojure language, I believe it is possible to tell in advance whether your problem will cleave cleanly into a part that can be succinctly and adequately (in performance terms) expressed in Clojure and a part that needs doing in Java.

    • You can go for Scala lite: writing Java idioms in Scala. You'll gain some brevity, a syntax that's easier on the eye, and a coherent albeit complex type system.
    • There is no such thing as Clojure lite: writing Java idioms in Clojure is utterly pointless. All you'll get is slow Java that's hard to understand because it cuts across the grain of the idioms used to express it.

    Scala has been said to be Java done right. Clojure is nothing like Java. You might say that it is Lisp done right - a bold, some would say preposterous, claim - which may turn out to be true.

提交回复
热议问题