In my experience C++ is the default language in finance because of legacy reasons and because they don't know any better. This was only a couple of years ago and I saw some horrendously poorly written C++ code--virtually no comments, early 90's style ("let me tell you about the STL"), no comments for hundreds of lines--that was being used in production to value mortgage bonds worth tens of billions of dollars. The group I was in had switched to using Python with Numpy, and was much more productive for it.
Why is C++ still a very popular language in quantitative finance?
21–30 of 51 posts
Re: Why is C++ still a very popular language in quantitative finance?
#22Template 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...
C++ template metaprogramming gives you most of the expressivity of generic programming without paying a large runtime penalty (because the resolution still occurs at compile time, the compiler can take advantage of this). This is in contrast to other languages, where run-time generic programming leads to performance penalties.
Now, as the stereotypical example of how C++ template metaprogramming can actually beat standard C programming, compare the performance of C qsort with C++ std::sort.
Re: Why is C++ still a very popular language in quantitative finance?
#23Earlier quoted context omitted.
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.
As for speed, with benchmarking every thing is in the details and while GC can be made to run fast the actual speed depends on the access patterns, the cache and when memory is used (and for how long).
In addition in C++ you can put quite a lot of things on the stack (that is actually how you make a smart-pointer) which is always going to be much, much faster than anything on the heap.
Re: Why is C++ still a very popular language in quantitative finance?
#24Earlier quoted context omitted.
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.
Depending on how many cores you use, what processor you use, and other use cases (e.g. copy-on-write, which is free with RC and super expensive with GC), one of them can be significantly faster than the other. But for a non-specific use case, it has been my experience that they are roughly equivalent.
The place where GC consistently excels is the "no random pauses" - most GCs will occasionally need to stop the world, even when they can mostly do incremental collections. Note that this does not mean they are slower - it is just that the overhead tends to be concentrated in bursts instead of uniformly spread out as in RC.
The place where RC consistently excels is reference loops, and less dependence on implementation robustness.
Re: Why is C++ still a very popular language in quantitative finance?
#25It always amuses me the way people treat C++ like it's some kind of dark, corrupting magic that no right thinking person would use.
Yes, learning C++ is a pain. And it will bite even its expert handlers pretty badly occasionally. But the kind of maintenance overhead suggested by the stackexchange question really isn't there. For non-trivial code (as in the example here) the maintenance and correctness burden of the problem itself is going to be far higher than that of the programming environment.
So yes: just say no to C++ for web server middleware, system maintenance scripting, probably most GUI work, etc... But for the truly hard stuff, I honestly don't see much advantage to anything else in particular. And as pointed out earlier, C++ can be deployed as a straightfoward program or shared library on everything with zero dependencies, and that's a HUGE advantage vs. languages with elaborate runtimes.
Re: Why is C++ still a very popular language in quantitative finance?
#26Earlier quoted context omitted.
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...
I didn't use the word 'powerful' because powerful generally refers to expressivity. I'm most interested in performance. C++ template metaprogramming gives you most of the expressivity of generic programming without paying a large runtime penalty (because the resolution still occurs at compile time, the compiler can take advantage of this). This is in contrast to other languages, where run-time generic programming lea…
Re: Why is C++ still a very popular language in quantitative finance?
#27It always amuses me the way people treat C++ like it's some kind of dark, corrupting magic that no right thinking person would use.
To be fair, C++ is a mess. It is, however, a very capable mess with extremely broad adoption and compatibility on pretty much every platform anywhere. Yes, learning C++ is a pain. And it will bite even its expert handlers pretty badly occasionally. But the kind of maintenance overhead suggested by the stackexchange question really isn't there. For non-trivial code (as in the example here) the maintenance and correctn…
C++, IMO, is not alone in that: XML, Unicode, multi-threaded programming using condition variables and mutexes, integer modulo arithmetic, date/time libraries, IEEE floating point, etc.
The good thing of all of them is that they solve complex real-world problems. The 'bad' thing is that they are more complex than other technologies that solve the same problem, partly.
Re: Why is C++ still a very popular language in quantitative finance?
#28C++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 soft…
[1]: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n334...
Re: Why is C++ still a very popular language in quantitative finance?
#29C++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 soft…
But C++11 has improved on that aswell, as much as possible within the old framework.