Skip to content

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

Comments

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...

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 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.

Not all expressive generic programming techniques have run time costs. The parent poster mentioned Lisp, in which macros are also usually expanded at compile time. Furthermore, Template Haskell offers type-safe compile time metaprogramming.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.