From owner-freebsd-chat@FreeBSD.ORG Thu Apr 20 17:23:45 2006 Return-Path: X-Original-To: freebsd-chat@freebsd.org Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2691416A401 for ; Thu, 20 Apr 2006 17:23:45 +0000 (UTC) (envelope-from strick@covad.net) Received: from mail871.megamailservers.com (mail871.carrierinternetsolutions.com [69.49.106.81]) by mx1.FreeBSD.org (Postfix) with ESMTP id 353AA43D53 for ; Thu, 20 Apr 2006 17:23:43 +0000 (GMT) (envelope-from strick@covad.net) X-POP-User: strick.covad.net Received: from mist.nodomain (h-67-101-99-172.snfccasy.dynamic.covad.net [67.101.99.172]) by mail871.megamailservers.com (8.13.6/8.12.9) with ESMTP id k3GAXZTl001137 for ; Sun, 16 Apr 2006 06:33:36 -0400 Received: from mist.nodomain (localhost [127.0.0.1]) by mist.nodomain (8.13.3/8.13.3) with ESMTP id k3GAXZCO001786 for ; Sun, 16 Apr 2006 03:33:35 -0700 (PDT) (envelope-from dan@mist.nodomain) Received: (from dan@localhost) by mist.nodomain (8.13.3/8.13.3/Submit) id k3GAXZSK001785 for freebsd-chat@freebsd.org; Sun, 16 Apr 2006 03:33:35 -0700 (PDT) (envelope-from dan) Date: Sun, 16 Apr 2006 03:33:35 -0700 (PDT) From: Dan Strick Message-Id: <200604161033.k3GAXZSK001785@mist.nodomain> To: freebsd-chat@freebsd.org Subject: Re: Why is not more FreeBSD software written in C++? X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 Apr 2006 17:23:45 -0000 OOPS ... I accidentally sent off that last message on the subject: Re: Why is not more FreeBSD software written in C++? while trying to run ispell on it. In addition to fixing a bunch of typos that I trust everyone will just ignore, I wanted to add: I really like C++ but I am not sure how to deal with the performance problems. They are not so trivial that they can always be ignored. I have done a few casual benchmarks. Code that uses C++ strings can run up to 100 times slower than functionally equivalent code that uses C character arrays (though such an extreme case is surely pathological). Code that uses C++ iostreams typically runs somewhere between 2 and 9 times slower than code that uses C stdio. You don't believe me? Compare cout << ' '; to putchar(' '); and weep. Of course most programs presumably spend only a small part of their runtime on strings and i/o. I wish I could say the the advantages of C++ are so great as to outweigh any possible performance glitch, but I can't quite bring myself to do that. Dan Strick --------------------------------------------------------------------- P.S. In case you missed the message to which this one applies, here it is: Most software is probably written in C rather 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 distributions. 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 implementation details. A C++ program that avoids using simplifying standard library facilities by reimplementing them is arguably bad C++.