Date: Sun, 16 Apr 2006 02:37:06 -0700 (PDT) From: Dan Strick <strick@covad.net> To: freebsd-chat@freebsd.org Subject: Re: Why is not more FreeBSD software written in C++? Message-ID: <200604160937.k3G9b6UD001237@mist.nodomain>
next in thread | raw e-mail | index | archive | help
Most software is probably written in C ranther than C++ because fewer programmers are familiar with C++. Note that this means C++ programs are in a practical sense less portable and more difficult to maintain even though the GNU C++ compiler is a good implementation, widely available and pretty much standard in all unix-like OS distribution. It may be just as well that most software is written in C. Programs written in C probably run only a very few percent slower when compiled as C++. (I am assuming the programs are written in the common subset language.) Even language features peculiar to C++ are generally implemented quite efficiently. Programs written in a good C++ style naturally use C++ standard library facilities (classes, private functions, templates) that can be expensive. Since C++ programmers generally do not consider the underlying implementations (arguably a very good thing), significant unintended run-time overhead can result. For example, I once rewrote a program in C++ and discovered the C++ version ran about 5.5 times slower than the original C version. My "mistake": I used the C++ string and iostream classes. After rewriting the C++ program to use C stdio instead of C++ iostreams and replacing C++ string classes with C character arrays, the C++ program ran only 1.5 times slower than the C program. I must note that the C++ version was in some ways a lot cleaner than the C version. The problem is that a major reason for using C++ in the first place is to take advantage of these specific C++ library features. A major motivation for the development of C++ itself was to facilitate code sharing by better isolating main program code from library implemention details. A C++ program that avoids using simplifying standard library facilities by reimplementing them is arguably bad C++.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200604160937.k3G9b6UD001237>