Linked by Amjith Ramanujam on Wed 20th Aug 2008 19:37 UTC
General Development DevX interviewed Bjarne Stroustrup about C++0x, the new C++ standard that is due in 2009. Bjarne Stroustrup has classified the new features into three categories Concurrency, Libraries and Language. The changes introduced in the Concurrency makes C++ more standardized and easy to use on multi-core processors. It is good to see that some of the commonly used libraries are becoming standard (eg: unordered_maps and regex).
Thread beginning with comment 327473
To read all comments associated with this story, please click here.
what is C++ best for?
by project_2501 on Wed 20th Aug 2008 21:47 UTC
project_2501
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?

RE: what is C++ best for?
by ebasconp on Wed 20th Aug 2008 22:19 in reply to "what is C++ best for?"
ebasconp Member since:
2006-05-09

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

Reply Parent Bookmark Score: 9

RE[2]: what is C++ best for?
by danieldk on Wed 20th Aug 2008 22:22 in reply to "RE: what is C++ best for?"
danieldk Member since:
2005-11-18

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.


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

Reply Parent Bookmark Score: 6

RE[2]: what is C++ best for?
by CrLf on Wed 20th Aug 2008 23:11 in reply to "RE: what is C++ best for?"
CrLf Member since:
2006-01-03

Template metaprogramming is the most elegant and powerful way to deal with a lot of problems.


I hope you were being ironic...

Reply Parent Bookmark Score: 3

RE: what is C++ best for?
by jacquouille on Wed 20th Aug 2008 22:19 in reply to "what is C++ best for?"
jacquouille Member since:
2006-01-02

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

Reply Parent Bookmark Score: 9

RE[2]: what is C++ best for?
by project_2501 on Wed 20th Aug 2008 23:20 in reply to "RE: what is C++ best for?"
project_2501 Member since:
2006-03-20

"thousands of vectors" - sure but why not use C structs .. I'm trying hard to understand this.

Reply Parent Bookmark Score: 0

RE[2]: what is C++ best for?
by tyrione on Wed 20th Aug 2008 23:41 in reply to "RE: what is C++ best for?"
tyrione Member since:
2005-11-21

Fortran isn't touched when it comes to precision when doing Numerical Analysis.

Reply Parent Bookmark Score: 2

RE: what is C++ best for?
by danieldk on Wed 20th Aug 2008 22:19 in reply to "what is C++ best for?"
danieldk Member since:
2005-11-18

For years I have struggled to understand where C++ fits into the landscape.


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

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

Reply Parent Bookmark Score: 6

RE[2]: what is C++ best for?
by ashigabou on Thu 21st Aug 2008 02:16 in reply to "RE: what is C++ best for?"
ashigabou Member since:
2005-11-11

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.


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.

Reply Parent Bookmark Score: 1

RE: what is C++ best for?
by WorknMan on Wed 20th Aug 2008 22:42 in reply to "what is C++ best for?"
WorknMan Member since:
2005-11-13

Where is C++ a compelling solution?


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

Reply Parent Bookmark Score: 8

RE[2]: what is C++ best for?
by spynode on Thu 21st Aug 2008 03:49 in reply to "RE: what is C++ best for?"
spynode Member since:
2008-08-17

With you all the way. Even about the Opera.

Reply Parent Bookmark Score: 1

RE[2]: what is C++ best for?
by phoenix on Thu 21st Aug 2008 04:16 in reply to "RE: what is C++ best for?"
phoenix Member since:
2005-07-11

If you want to write a cross-platform app, figure out how Opera does it and do it like they do.


Hrm, that would be using QT, which is written in C++. ;)

Reply Parent Bookmark Score: 5

RE[2]: what is C++ best for?
by FunkyELF on Thu 21st Aug 2008 08:47 in reply to "RE: what is C++ best for?"
FunkyELF Member since:
2006-07-26

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?


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.

Reply Parent Bookmark Score: 2

RE: what is C++ best for?
by OSGuy on Wed 20th Aug 2008 22:53 in reply to "what is C++ best for?"
OSGuy Member since:
2006-01-01

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

Reply Parent Bookmark Score: 3

RE[2]: what is C++ best for?
by google_ninja on Thu 21st Aug 2008 00:29 in reply to "RE: what is C++ best for?"
google_ninja Member since:
2006-02-05

C++ is one of the more popular ALGOL based languages, it is hardly the base of all languages.

Reply Parent Bookmark Score: 3

RE: what is C++ best for?
by _LH_ on Thu 21st Aug 2008 00:09 in reply to "what is C++ best for?"
_LH_ Member since:
2005-07-20

Where is C++ a compelling solution?


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.

Reply Parent Bookmark Score: 3

RE: what is C++ best for?
by Vanders on Thu 21st Aug 2008 10:05 in reply to "what is C++ best for?"
Vanders Member since:
2005-07-06

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.

Reply Parent Bookmark Score: 3

RE: what is C++ best for?
by Abacus_ on Thu 21st Aug 2008 19:56 in reply to "what is C++ best for?"
Abacus_ Member since:
2006-12-08

For years I have struggled to understand where C++ fits into the landscape.
[...]
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 .

Reply Parent Bookmark Score: 1

RE: what is C++ best for?
by marafaka on Fri 22nd Aug 2008 09:02 in reply to "what is C++ best for?"
marafaka Member since:
2006-01-03

C++ is a great C with namespaces ;) Other than that ... if ones experience of programming languages is limited to C++ it's not that easy to get out of that tar-pit. But you know all of that...

Reply Parent Bookmark Score: 1