Live data from Hacker News

Why is C++ still a very popular language in quantitative finance?

quant.stackexchange.com

11–20 of 51 posts

Re: Why is C++ still a very popular language in quantitative finance?

#11
post #8

C++11 is a very modern language. It seems to be moving faster than Java these days.

Exactly, many critiques of C++ are well and truly obsolete. What are the practical advantages of Java's GC over C++'s smart pointers? Actually not much, so why carry that overhead.

Plus the elephant in the corner of the room is that actually, write-once-run-anywhere in the real world turns out to be, write on Linux on x64, run on Linux on x64. In the Java world, they like to run one VM (JVM) inside another (on Xen or whatever). Again why schlep all that around? The world is turning back to native code, for good reason.

Re: Why is C++ still a very popular language in quantitative finance?

#12
post #9

It appears to be mostly inertia. People learned C++ and a few relevant specialized libraries, so they keep on them. Outside of a few relatively narrow topics like high frequency trading, trading algorithms for direct market access and solving optimizations, the speed of C++ is not needed. As a result I am observing more code development occurring in higher level languages such as Python, R, Matlab and SecDb/Slang. Ex…

SecDB/Slang outside of Goldman?

Re: Why is C++ still a very popular language in quantitative finance?

#13
post #12
post #9

It appears to be mostly inertia. People learned C++ and a few relevant specialized libraries, so they keep on them. Outside of a few relatively narrow topics like high frequency trading, trading algorithms for direct market access and solving optimizations, the speed of C++ is not needed. As a result I am observing more code development occurring in higher level languages such as Python, R, Matlab and SecDb/Slang. Ex…

SecDB/Slang outside of Goldman?

No SecDB/Slang outside of Goldman because it is completely proprietary, but the single platform vision within has no signs of abetting.

Re: Why is C++ still a very popular language in quantitative finance?

#15
post #8

C++11 is a very modern language. It seems to be moving faster than Java these days.

To be "very modern" there would have to be a replacement for the antiquated header files system. Writing function signatures twice isn't modern. Writing all code that uses templates in header files isn't modern. Waiting minutes or hours for my code to compile isn't modern. C++ carries a lot of baggage from the past and that's how it was conceived from the beginning. I'm still using C++ because it's efficient and software is made for users after all.

Re: Why is C++ still a very popular language in quantitative finance?

#16
post #11
post #8

C++11 is a very modern language. It seems to be moving faster than Java these days.

Exactly, many critiques of C++ are well and truly obsolete. What are the practical advantages of Java's GC over C++'s smart pointers? Actually not much, so why carry that overhead. Plus the elephant in the corner of the room is that actually, write-once-run-anywhere in the real world turns out to be, write on Linux on x64, run on Linux on x64. In the Java world, they like to run one VM (JVM) inside another (on Xen or…

Smart pointers use a lot of memory and some implementations, like boost::shared_ptr are heap based. One thing I want from C++ is efficiency, so I don't subscribe to the recently popular idea of using smart pointers everywhere. A Java reference uses 32 bits even on a 64 bit machine (below 32GB). A shared_ptr uses 4 times that (the first one does).

Re: Why is C++ still a very popular language in quantitative finance?

#17

It always amuses me the way people treat C++ like it's some kind of dark, corrupting magic that no right thinking person would use.

It isn't?

I always used to think of compiler design and advanced algorithms as dark magic; however, I now understand that that was just based off of unfamiliarity with the concepts. I suspect that much of that is the same with C++ as well.

Re: Why is C++ still a very popular language in quantitative finance?

#18
post #11
post #8

C++11 is a very modern language. It seems to be moving faster than Java these days.

Exactly, many critiques of C++ are well and truly obsolete. What are the practical advantages of Java's GC over C++'s smart pointers? Actually not much, so why carry that overhead. Plus the elephant in the corner of the room is that actually, write-once-run-anywhere in the real world turns out to be, write on Linux on x64, run on Linux on x64. In the Java world, they like to run one VM (JVM) inside another (on Xen or…

What are the practical advantages of Java's GC over C++'s smart pointers? Actually not much, so why carry that overhead.

Smart pointers aren't free, memory or otherwise.

The syntactic overhead of declaring smart pointers is one. Say what you want, but the verbosity of these declarations is quickly tiring, and ergonomics is relevant. typedef's help, but that leads to the next bit, which is that smart pointers are leaky abstractions in the sense that they are never going to be directly interchangeable with a regular C++ pointer. So the abstraction breaks down (if only a little) anytime you need one.

Destruction and RAII have benefits that it's harder to leak memory, but they force you into awkward contortions where you may potentially need more copies than usual, and because copying is an O(n) process in some instances, this can result in the contortions changing the complexity characteristics of data structures or algorithms. Move semantics can alleviate this greatly, however, and they are a welcome addition, as are many other things in C++11 (moves, constexpr, for-each, better enumerations, lambdas, and auto are all very welcome.)

And finally: the massive, unadultered proliferation of reference types quickly becomes an incredible load intellectually. As a programmer, you likely don't care a ton about the sharing semantics of any individual object and whether it's smart or unique or whatever - that is something that can be done automatically with no intervention on your part.

If it turns out you do care about these things greatly, because they are important to your actual task at hand, it is likely C++ may be a good choice. I have written C++ on the job, and have gone from nightmarish code to much nicer code, and it is a suitable tool for many issues.

The counterargument, which is valid too I think, is that sharing semantics form an important part of an API - you can determine whether or not you own a object because it's unique, or whether you should be careful, as it's shared. But this of course a benefit that extends to any typed data, in any typed language (that's worth its salt.)

But people who throw around "just use a smart_ptr and you're like, just as good as Java, obviously" aren't really helping. There's lots of valid points for both sides.

Again why schlep all that around?

Because in a vast majority of cases, it's irrelevant and your time and money is probably just as well spent somewhere else.

The world is turning back to native code, for good reason.

What indications do you have for this? I suppose iOS is a good case example, for one. But the massive amount of web property and the needs of those institutions alone for example, shows that while the world does need native code, it's not turning back to it with reckless abandon.

Futhermore, native code and garbage collection have nothing to do with each other. And the JVM isn't anywhere near the best example: Java having a very heavy per-object overhead (something like 5-7 words per object for heap metadata) doesn't help memory benchmarks in the slightest, although the JVM does have impressive compilation facilities.

But if you want a much better baseline, compare to something like LuaJIT, that gets comparably close to even C++ with only a tiny memory footprint, or compare it to something like GHC where the collector is remarkably robust, and the per-object overhead can be significantly decreased (as all objects instead only have 1 word overhead, and unlike a language like Java, you can totally unpack structures of composite, non-primitive types, meaning new data types can come 'totally free.')

Re: Why is C++ still a very popular language in quantitative finance?

#19
post #14

Template metaprogramming still solves certain problems better than other solutions. If it is not used obsessively, then there are better languages

What kinds of problems? I can't easily think of problems where C++ templates are more powerful than metaprogramming facilities of high level languages like lisp...

Re: Why is C++ still a very popular language in quantitative finance?

#20
post #11
post #8

C++11 is a very modern language. It seems to be moving faster than Java these days.

Exactly, many critiques of C++ are well and truly obsolete. What are the practical advantages of Java's GC over C++'s smart pointers? Actually not much, so why carry that overhead. Plus the elephant in the corner of the room is that actually, write-once-run-anywhere in the real world turns out to be, write on Linux on x64, run on Linux on x64. In the Java world, they like to run one VM (JVM) inside another (on Xen or…

Aren't C++ smart pointers essentially reference counting? That's well known to be much slower than well implemented GC.
Post reply on HN