Date: Wed, 19 Apr 2006 03:04:38 -0700 From: "David Schwartz" <davids@webmaster.com> To: <freebsd-chat@freebsd.org> Subject: RE: Why is not more FreeBSD software written in C++? Message-ID: <MDEHLPKNGKAHNMBLJOLKIEJFLGAB.davids@webmaster.com> In-Reply-To: <44415038.4020101@jamesbailie.com>
next in thread | previous in thread | raw e-mail | index | archive | help
> Efficiency is of prime importance in systems programming. I could not disagree more, depending upon what you're really trying to say. Performance may have been paramount ten years or more ago, and there's certainly a very small amount of code where performance really is the most important thing. But in the vast majority of cases, even in non-kernel systems programming, the ability to maintain, understand, and verify that the code is correct is *way* more important. Obviously, gratuituous inefficiency doesn't help anything. But in the vast majority of cases where you have to choose between efficiency and almost anything else, you should chose the other thing. The is especially true for the alleged inefficiency of C++ in comparison to C. You can shoot yourself in the foot with either language, of course. But proper use of C++ features does *not* measurably impact performance on modern processors with modern compilers. Of course, you can use OOP to write code that's harder to maintain, understand, and verify too. That's obviously not good. C++ doesn't force you to use any of its features. It just gives you more possibilities, each of which you are free to use only when it makes sense. Also, to save a separate post, I'd say to: >Why did I even ask the question? I perceive correctness as a big problem when >programming in C. It is difficult to know for sure that a C program is >correct, since there are no guards against mistakes like string buffer >overflows, erroneous pointer handling or memory allocation. C++ is of course >far from being a golden bullet, but it does solve some of the problems (using >C++ strings instead of char* generally means you don't have to worry about >string buffer overflows). Well, you can do anything in any language. However, C++ does make some things a lot easier. For example, you can plug in a debug version of your string class and get extra checks in all string operations that use it. This is a lot harder to do in C. In a release build, you can get the string class to inline to the point where there is no measurable performance hit. (In fact, if you do clever allocation tricks, you can make the string class pay for itself. Not that you couldn't do this in C, you just are much less likely to simply because it's harder.) The reasons C is used over C++ in non-kernel code are basically three: 1) C is more widely known than C++. Choosing C++ reduces the number of people who are likely to work on a project. 2) When the language was chosen for a lot of projects, C++ wasn't available, wasn't stable, or had specific implementation issues (such as slow compilation, poor optimization, and so on). 3) A lot of people are illogically biased against C++. The two largest forms are "C is better than C++ because it doesn't have any of the defects C++ added to C" and "C++ has poor performance compared to C, and performance is the most important thing". Largely, these arguments quickly collapse into the equivalent of "I don't know C++ as well as I know C", reducing this to reason 1. DS
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?MDEHLPKNGKAHNMBLJOLKIEJFLGAB.davids>