On Performance and Java Interoperability: Clojure vs. Scala

Viewed 31297

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 Answers

The November 2010 issue of PragPub discusses Clojure-Java interoperability. Calling Java methods is straightforward, but extending Java classes/interfaces is quite different.

Scala on the other hand is much closer to Java. Scala-Java interoperability is elaborated at http://www.codecommit.com/blog/java/interop-between-java-and-scala

Calling Java code and extending Java classes/interfaces works the same way as calling Scala code. Some pain points might be some edge cases of dealing with Java's generics, because Scala's type system is much stronger than Java's. Creating getters and setters following the Java Bean convention requires an annotation.

Calling Scala from Java is most of the time straightforward, but for example Scala's companion objects requires knowing how they are compiled to bytecode. Also using traits with non-abstract methods from Java should be complicated, and calling methods with special characters would require knowing how they are encoded in the bytecode.

Related