As a Linux (server side) developer, I don't know where and why should I use C++.When I'm going for performance, the first and last choice is C.When performance isn't the main issue, programming languages like Perl and Python would be good choices.Almost all open source applications I know in this area have been written in C, Perl, Python, Bash script, AWK or even PHP, but no one uses C++.I'm not discussing other areas like GUI or web applications, I'm just talking about Linux, CLI and daemons.Is there any satisfactory reason to use C++?
Is there any reason to use C++ instead of C, Perl, Python, etc.?
programming languages;c++;c;linux;perl
When I'm going to performance, the first and last choice is C.And thats where you should back up. Now, I cannot, at all, speak for server development. Perhaps there is indeed no compelling reason to prefer C++ over the alternatives.But generally speaking, the reason to use C++ rather than other languages is indeed performance. The reason for that is that C++ offers a means of abstraction that has, unlike all other languages that I know, no performance overhead at runtime.This allows writing very efficient code that still has a very high abstraction level.Consider the usual abstractions: virtual functions, function pointers, and the PIMPL idiom. All of these rely on indirection that is at runtime resolved by pointer arithmetic. In other words, it incurs a performance cost (however small that may be).C++, on the other hand, offers an indirection mechanism that incurs no (performance) cost: templates. (This advantage is paid for with a (sometimes hugely) increased compile time.)Consider the example of a generic sort function.In C, the function qsort takes a function pointer that implements the logic by which elements are ordered relative to one another. Javas Arrays.sort function comes in several variants; one of them sorts arbitrary objects and requires a Comparator object be passed to it that works much like the function pointer in Cs qsort. But there are several more overloads for the native Java types. And each of them has an own copy of the sort method  a horrible code duplication.Java illustrates a general dichotomy here: either you have code duplication or you incur a runtime overhead.In C++, the sort function works much like qsort in C, with one small but fundamental difference: the comparator that is passed into the function is a template parameter. That means that its call can be inlined. No indirection is necessary to compare two objects. In a tight loop (as is the case here) this can actually make a substantial difference.Not surprisingly, the C++ sort function outperforms Cs sort even if the underlying algorithm is the same. This is especially noticeable when the actual comparison logic is cheap.Now, I am not saying that C++ is a priori more efficient than C (or other languages), nor that it a priori offers a higher abstraction. What it does offer is an abstraction that is very high and incredibly cheap at the same time so that you often dont need to choose between efficient and reusable code.