On Performance and Java Interoperability: Clojure

2020-05-11 09:48发布

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 explanation on when it comes to comparing both Clojure with Scala:

1.) Which of the two languages is generally faster? I realize that this will vary from one language feature to another but an general assessment of performance would be helpful. For example: I know that Python dictionaries are really fast. But as a whole, it is a much slower language than Java. I don't want to go with Clojure and run into this problem down the road.

2.) How is interoperability with Java? All I have read so far is that Scala has native collections types that make it a bit clumsy to integrate with a large Java code-base, whereas Clojure follows a simple Iterable/Iterator-centric way to inter-operate with Java classes. Any more thoughts/details on this?

Ultimately, if it is a close enough draw between clojure and scala, I might try them both. One thing about Clojure is the language seems very simple. But then again, Scala has a very flexible type system. But, I know that Scala is fast (based on multiple personal accounts). So, if Clojure is significantly slower: I'd like to know sooner rather than later.

8条回答
干净又极端
2楼-- · 2020-05-11 10:36

The stats produced by the "Computer Language Benchmark Game" are about the best you're probably going to find.

They are in-depth and you can compare many languages. The problem is that they don't cover Clojure :(

That said, it's pretty easy to submit anything--it's all open source.

The stats do say that Scala is pretty damn quick.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2020-05-11 10:42

Note that Clojure and Scala are two totally different types of programming languages - Clojure is a functional Lisp-like language, it is not object oriented. Scala is an object oriented language which has functional programming features.

In my opinion, the features and concepts of a language (functional, OO, ...) are much more important criteria for choosing a language than the performance (of a particular implementation of that language) - altough I understand that you don't want to get trapped into a language for which there is no well-performing implementation available.

I'd go for Scala, because it is object oriented but also allows you to learn functional programming (if you're interested in that). On the other hand, if you don't care about OO and you want to learn "pure" functional programming, try Clojure.

查看更多
登录 后发表回答