About Java Efficiency and Compatibility: Clojure vs. Scala

I have already read various Clojure vs. reports Scala, and although I understand that both have their place. There are several considerations that I did not get a full explanation when it comes to comparing both Clojure with Scala:

1.) Which of the two languages ​​is usually faster? I understand that this will differ from one language function to another, but a general assessment of effectiveness will be useful. For example: I know that Python dictionaries are very fast. But overall, it is much slower than the Java language. I do not want to go with Clojure and face this problem in the future.

2.) How does it interact with Java? All I have read so far is that Scala has its own collection types that make it a bit awkward to integrate with a large Java base, while Clojure follows the simple Iterable / Iterator method for interacting with Java classes. Any thoughts or details about this?

Ultimately, if it's close enough between Clojure and scala, I can try both of them. One thing about Clojure is a language that 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 much slower: I would like to know sooner rather than later.

+80
java performance scala jvm clojure
01 Oct '09 at 21:54
source share
8 answers

I think any language will be fast enough for you. When comparing Python and Java, it seems a little unreasonable to blame the language for speed differences. Java compiles JIT (except for mobile devices *), while Python is interpreted. Just because both options for using bytecode do not mean that implementations will even have remotely comparable performance. But both Scala and Clojure are JVM languages, so they should have similar performance.

Scala has several implementation advantages over Clojure, and I expect somewhat better performance. Although Scala's static typing typically translates into a speed advantage over the Clojure duck type, Clojure supports a hint type that can speed up code significantly. Perhaps the usual Scala is faster than the usual Clojure, but you only need to optimize the bottlenecks. Most of the program execution time is generated by a small amount of actual code.

As for interop w / Java, Scala is closer to Java, but I'm sure both languages ​​interact well. In Clojure programming, Stuart Halloway writes: "[you can access] anything you could get from Java code."

And since Scala author Martin Odersky wrote the Sun Java compiler, I think that not a single ball was removed on the Scala side either. :-)

It would be difficult for you to choose the two best languages, although I also like Ruby. Why are you worried about which one to try? Why not try both of them? Scala is likely to be the “next Java,” while it's hard to imagine that Lisp will finally come out after not doing so for more than 50 years. But it is clear that Lisp is at its own unique level of abstraction, and Clojure is quite simple, so Scala + Clojure will not be much more complicated than just (quite complex) Scala and I'm sure you will be glad that you did it.

And in this respect they interact ...

* dalvik (android JVM) received the JIT compiler in version 2.2 in 2010

+71
01 Oct '09 at 22:27
source share

With the current JVM, Scala has the advantage of accounting for statically typed, as JVM support for dynamic typing is reflection-slow. In fact, one Scala function that must be implemented using the same methods, structural types, is often warned for this very reason.

In addition, Scala accepts volatile objects just fine, and some algorithms are faster to implement with volatility.

Since both Scala and Java are essentially class-based languages, they interact more easily. Or perhaps more smoothly. The Java class is a class for Scala, and the Scala class is a class for Java. Problems can arise when it comes to Scala singles or static Java elements, especially when they involve an infrastructure that assumes that everything will work in a certain way.

So, I would go with Scala on both of these accounts. Clojure is in many ways the best language, and it certainly has some very interesting features that are not yet presented (yet) on Scala, but you get such benefits that are fully functional. If you intend to do this, then Clojure is likely to be better. If you do not, you should probably stay with Scala.

+32
Oct. 01 '09 at 23:00
source share

Please note that Clojure and Scala are two completely different types of programming languages. Clojure is a functional Lisp-like language focused on non . Scala is an object-oriented language with functional programming functions.

In my opinion, the features and concepts of the language (functional, OO, ...) are much more important criteria for choosing a language than performance (the specific implementation of this language) - although I understand that you do not want to fall into the trap of a language for which there is no well-implemented implementation.

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

+21
Oct 02 '09 at 7:36
source share

Statistics from the Benchmark Game PC game show the best you are likely to find.

They are in-depth, and you can compare many languages. The problem is that they do not cover Clojure :(

However, it’s pretty easy to imagine anything — it’s all open source.

According to statistics, Scala is pretty damn fast.

+15
Oct 01 '09 at 22:42
source share
  • The idiomatic Scala is faster than the idiomatic Clojure, and will remain so.
  • Both Scala and Clojure fit easily on top of Java. She doesn’t sit under him.

If your code is critical or critical over the entire area, stick with Java. But this is not so, even if you think so.

The Benchmark Game computer language sheds little light on Clojure's true resource costs. No Clojure data structures. Functional and sequential abstractions are not displayed.

Clojure may seem simple. This is not so, but it is expressive. It can run five times slower than Java, but the source is five times smaller (YMMV). For most applications, this is a big win. But for some, and for some parts of many others, this is a devastating loss.

With experience with the Clojure language, I believe that it can be said in advance whether your problem will be cleaner to clean in the part that can be concise and adequate (in terms of performance) expressed in Clojure, and the part that needs to be done in Java.

  • You can go to Scala lite: write Java idioms in Scala. You will get some brevity, a syntax that is easier on the eye, and a consistent though complex type system.
  • There is no such thing as Clojure lite: writing Java idioms in Clojure is completely pointless. All you get is slow Java, which to understand, because it crosses the grain of idioms used to express it.

Scala is said to run Java correctly. Clojure is not like Java. You could say that this Lisp is done correctly - in bold, some will say that this is ridiculous, a statement that may turn out to be true.

+13
Jun 06 '14 at 20:02
source share

Interaction, I can’t speak for Clojure, but I expect him to be in a similar situation like Scala.

It is trivially easy to call Java from Scala.

It's easy to call Scala from Java, as long as you agree with your external API to the common points between Scala and Java. For example, a Scala object is used in some ways as static methods in Java, but they are not the same thing. Scala classes can be compiled into several classes with names that look funny in Java.

You do not want to mix and match a lot. A build component in Scala or Clojure that uses many Java libraries is very possible. Of course, you can access this component with Java, but what you are not going to do is try to use the Scala API intended for use by Scala Java programs.

SVN claims that "CVS is done right." In my opinion, Scala is Java done right.

+9
Oct 02 '09 at 7:47
source share

The November release of PragPub, released in November 2010, discusses the functionality of Clojure -Java. Calling Java methods is simple, but extending Java classes / interfaces is completely different.

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

Calling Java code and extending Java classes / interfaces works just like calling Scala code. Some extreme pains can be some extreme cases of working with Java generics, because a system like Scala is much stronger than Java. Creating getters and setters by Java Bean requires annotation .

Calling Scala from Java is simple in most cases, but, for example, Scala companion objects require knowledge of how they are compiled into bytecode. In addition, using traits with non-abstract methods from Java should be difficult, and calling methods with special characters requires knowing how they are encoded in bytecode.

+3
Feb 10 2018-11-22T00:
source share

Now it (as of May 2010) stands on the last branch of 1.2 Clojure - this includes a lot of additional support for primitive types and static typing (using various types of prompts and protocols).

I understand that you can use these functions when you need it to get a speed equivalent to writing the exact same code in pure Java.

+1
May 18 '10 at 15:07
source share



All Articles