Thursday, 31 December 2009

Java for Quants? Step 2

Following up the conversation, another LinkedIn member, Daniel D wrote:


Some personal comparisons between Java and C++.
1. Advanced, mature generic programming (templates); Java 1.5 seems to be an afterthought, I suspect it is not even wrong.


Daniel is right. It is an after thought. You want "real" and nice templates, use Scala (runs on the JVM)


2. Memory management is deterministic in C++ (Garbage collectors are non-deterministic)


Again, I agree. However, does it matter? When I write C++ code, I have yet to find a pattern where I need the deterministic behavior that Daniel is talking about; in Java, you can always put the reference to null, or use fancier weak references classes if needed; or use jRockit realtime, or start experiencing with G1.


3. Language features; C++ supports modular programming, in addition to OOP and GP. In Java everthing is an *object*; very convenient, but too restrictive


Well, yes and no. Too much to talk about here. Not everything is an object, like primitive types, but they have a type, ie, you can write int.class if you want to. Scala is much more modular, but everything is an object in Scala. But that does not bother me.


4. Java does not support operator overloading (cannie say Matrix m3 = m1*m2)


Use Scala.


5. C++ interfaces well with the hardware and software drivers


Java as well, via JNI.


6. C++ is terse; Java tends to be verbose


It all depends on the programmer, so not an argument, but in any case, want to use a concise language on the VM? Use Scala.

Wednesday, 30 December 2009

Java for Quants?

There was an lively debate on LinkedIn with respect of using Java for Quantitative work.
As usual, some people were quick at pointing out Java's “slowness” compared to C++.
Obviously, yours truly, tried to demystify that point.

Java is as fast and sometimes faster than C++. Do not believe me, try it out for yourself. Try Java 6, in server side mode with asynchronous garbage collection, the performance will be mind-blowing, or at least, if you were sceptical, will be unbelievable.
Try java -server +XX:UseConcMarkSweepGC with a program, develop the same one in C++ and compare the performance between the two.
Make sure you read this entry first.

My answer to Java for quants is not about the language but about the architecture and design.
It does make sense to write a quant lib in C/C++, why? Because of speed, no – because if speed is your concern, you'd go C/ASM or a hardware solution; because of ease of use with other systems: writing a .dll or .so allows your lib to be called from .NET, Java (via JNI), Excel, etc.

People are very sensitive about C++ vs. Java – what about trying it yourself and be objective?

Also, let's not talk about Java only, it is also and mainly about the VM, which supports many other languages, in particular Scala, OCAML, Jruby, ...

Sunday, 20 December 2009

Joyeux Noel everyone

Merry Christmas and Happy New Year

Blog Archive