From: Bill Kelly Date: 2005-04-07T06:13:45+09:00 Subject: Re: new! From: "Phlip" > > Steven Jenkins wrote: > > > I hesitate to feed language comparison threads, but this is wrong. The > > only person who can state with authority the design criteria for C++ is > > Bjarne Stroustrup, and he said "My initial aim for C++ was a language > > where I could write programs that were as elegant as Simula programs, > > yet as efficient as C programs." You can't conclude from this statement > > that elegance is secondary to efficiency. > > No advocacy is needed to discuss this - it's an axiom of C++'s design. If > you don't have a virtual destructor, and you delete thru a base class > pointer, you get undefined behavior. C++ programmers learn their art by > learning a humongous list of trivial ways to create undefined behavior. The > language won't do anything you don't explicitly tell it to; this gives > compilers freedom to optimize aggressively. Agreed. Reading Stroustrup, "You don't pay for what you don't use" was cited repeatedly as an unbreakable constraint governing the design of C++. That's why new [] has to be matched with delete [], - despite this being inconvenient and an easy pitfall for programmers. "You don't pay for what you don't use" trumps programmer convenience every time in C++. I think it's also one of the reasons C++ succeeded - because you *can* write C++ that's identically efficient to C when you need to. In the mid 90's I worked at a game shop that was wary of starting a new project in C++ because of rumors that C++ was inherently inneficient. What helped me get C++ approved for that project was to compile our previous game's C code base with the C++ compiler, and show that, apart from inconsequential things like some values stored in different register names, the disassembly between the C and C++ compiled versions was identical. "You don't pay for what you don't use" is an important aspect of C++ -- but it's also what contributes to it being a pain in the butt. :) Regards, Bill