To read all comments associated with this story, please click here.
Every major piece of commercial software is implemented in C++ including big open source projects [e.g. KDE].
I really do not know if it is implemented in C++, but I do not imagine Microsoft Office implemented in C [and worse implemented in Python, Ruby or C#].
I see all higher level programming languages to "tailor-made" software for business and enterprise operations, but C++ for the rest and I do not see a world full of commercial software implemented just in C# or Java.
C++ abstraction is several orders of magnitude higher than C's. Template metaprogramming is the most elegant and powerful way to deal with a lot of problems.
Edited 2008-08-20 22:25 UTC
Hey, as long as Sun's Hotspot Java VM is written in C++, there clearly is a place for C++
. For an extensive (and impressive) list of C++ applications see: http://www.research.att.com/~bs/applications.html
And don't forget the Joint Strike Fighter :p:
http://www.research.att.com/~bs/JSF-AV-rules.pdf
Just to give the one example where I have first-hand experience: mathematical software, such as vector/matrix libraries.
Here, one pursues two goals that are generally considered incompatible:
On the one hand, one wants to imitate math notation : "a = b+c*d" etc... this can be achieved with any object-oriented language through operator overloading and method chaining. The problem is that the passing of arguments and of return values, the evaluation of temporaries, etc, kill the performance.
On the other hand, one wants not only the best performance, but also optimal memory usage. For example, when you have a million of small vectors, you really want to make sure that each vector takes the minimum possible number of bytes. This rules out many object-oriented features, which are mandatory in many languages. For example, if your small vectors take only 8 bytes each, you definitely can't afford a vtable pointer which by itself takes 4 or 8 bytes!
This was just one example where C++ shines.
More generally, the full control that you get over the generated code, the template meta-programming (btw the C++0x spec is obviously reflecting the increasing importance of that paradigm), the "you only pay for what you use" design, make it a killer language for performance. For math software, it allows optimal performance (like C) with 5% the lines of code (I'm not making this up -- comparing the library i'm co-developing with existing C libraries. See http://eigen.tuxfamily.org/index.php?title=Benchmark)
Edited 2008-08-20 22:24 UTC
One obvious sweet spot is where performance is needed, or where there are constraints (e.g. memory constraints). As you mention, C is good in those departments as well, but there are some large advantages to C++. To give two examples (there are plenty more, but this is for the sake of the argument
): - RAII (Resource acquisition is initialization): since resources can be associated with objects, resources can be acquired in constructors and released in destructors. This makes it possible to bind resource use to the object lifetime. E.g. when an object is allocated on the stack, and it goes out of scope, the resources are automatically released as well. RAII is often not possible with OO languages that use a garbage collector, since there is no guarantee when objects will be garbage collected/destructed (if ever). In GC-ed languages, resources often have to be released explicitly.
- Templates: templates allow you to specify algorithms and data structures without one of three choices required in C: 1. tailor data structures/algorithms to one type (e.g. a sort algorithm for strings), 2. use void pointers (usually with some function pointer), or 3. rely on macros. In C++ you can write generic algorithms and data structures with strong typing enforced. The STL (Standard Template Library) and large parts of Boost are great samples of what can be done with template programming (and template metaprogramming).
[...]
For some practical scenarios, you can't beat a rapid development and rapid evolution language like Python.
As a general remark, I'd like to add that good C++ programmers can usually be as productive as good Java programmers (as some studies have shown, Google should be able to find them).
Additionally, C++ is an excellent language to write code where you need performance and tie it up with Python code (or your favorite dynamic language
). E.g. Boost.Python is excellent for creating Python bindings for C++ code.
). E.g. Boost.Python is excellent for creating Python bindings for C++ code. The problem is that it is so slow to compiler anything non trivial with boost.Python that is it is painful to develop with. I agree that in theory, it is nice, but I find it quite unusable in practice.
I personally believe the trend is toward doing as much as possible in scripting language, with some compiled code where needed, and moving away from scripting something which is essentially C++. Some core things (basic toolkits, etc...) will still be written in compiled languages for quite some time of course, but environments like python for scientific programming give you much more flexibility that what you can get by just wrapping a huge, inflexible C++ framework. Prototyping speed is a key factor, both in academic and in the private markets (finance, data analysis, etc...), and C++ is just so much behind for this that is cannot compete, even with top notch programmers.
When you want apps that aren't bloated and run fast. Case in point.. I downloaded an app several months ago written in Python (forget the name) that I could use to download Podcasts with. The thing ate up 22MB sitting idle in the system tray. I realize that RAM is cheap these days, but 22MB to sit and do next to nothing.. are you f**king kidding me?
And don't even get me started on Java. C# isn't much better either. I realize that these languages make it easier on developers, but as an end user, I say piss on all of 'em. If you want to write a cross-platform app, figure out how Opera does it and do it like they do.
Edited 2008-08-20 22:42 UTC
Because it was in the system tray it was probably using a graphical toolkit like GTK+ or QT.
Process monitors will incorrectly display the used RAM by including the size of shared libraries that may already be loaded in RAM.
Go look for some articles about KDE4 and memory usage. Linux will report it as using more than KDE3 even though it is actually much less.
Also, don't base your opinion of Python on one Python program, it may have been written bad. Things can go the other way to, if I based my Java opinion on just 2 java programs (eclipse and azureus), I might think that it was actually a good language and not the pile of crap that it actually is. Okay, I was only partly kidding about the Java part.
Your post mentions a few different languages. It will require writing a novel to explain the differences and the advantages of C++ over the languages you mentioned. Don't try to underestimate the power of C++ if you haven't learned the language and if that is the case, I strongly suggest you to learn it as C++ is pretty much the base of all programming languages.
P.S. C++ is also ideal for low level coding and personally I would rather use objects of classes rather than pure C functions.
Edited 2008-08-20 22:55 UTC
Quite often I've found myself in situations where C++ delivers performance comparable to C but is much more faster to work with as you can take abstractions further away from the actual hardware in a way which is not entirely unlike some popular scripting languages.
C++ is a good middle-ground between C and high-level languages, which makes it great for "high level" system programming: things like GUIs. The major advantage of C++ here is that it is easy to interface with C, which is the lowest common denominator for other languages to bind to, so if I write a library in C++ and export a C API from it, you can easily make use of my library from whatever language you like.
[...]
Where is C++ a compelling solution?
IMHO C++ is a compelling solution for larger projects in which runtime efficiency matters. C++ is e.g. well suited for embedded software. A more detailed discussion can be found here: C++ in Embedded Systems: Myth and Reality, http://www.embedded.com/98/9802fe3.htm .







Member since:
2006-03-20
For years I have struggled to understand where C++ fits into the landscape.
Can someone give me examples of problems where C++ is by far the best solution than other languages like C or Java or Python or Scheme or ...
For low level coding, sure C is ideal. For number crunching, Fortran makes good use of the limited scope of certain computational problems. For some practical scenarios, you can't beat a rapid development and rapid evolution language like Python. For interactive GUIs something like Smalltalk can be fun.
Where is C++ a compelling solution?