zaimoni
2/20/2008 9:20:00 PM
On 2008-02-20 19:55:32, Ido Yehieli <Ido.Yehieli@gmail.com> wrote:
> On Feb 20, 7:10 pm, Jeff Lait wrote:
> > No, it would be more wrong. Unless you are going to claim that "C++"
> > implies OOP, which it doesn't. I can write C-style code inside C++.
> > My use of // comments hardly makes it C++ (Indeed, for all I know //
> > comments are now part of C...) This, I presume, is why the two are
> > grouped together - it is very hard to look at the project and
> > determine from the outside if it is a "C" project or a "C++" project.
>
> Jeff, you are right that in some cases people write c++ in a way which
> is very similar to c. But in my experience it is normally not so. I
> also believe that code which is considered "good" c is not considered
> "good" c++. I would say that among most (or at least a very large
> portion) of modern c++ code bases, at least one of:
> * classes
> * exceptions
> * STL/Templates
>
> is used, each of which is fundamentally opposed to the c way of doing
> things.
You could, like, actually *name* something where C++ and C actually opposed each
other, instead of C++ providing syntactic sugar for doing things the C way.
Like the major differences I have to consider for my own projects:
* C vs C++ I/O (and with the way C++ stream implementations bloat executable
size, I strongly recommend C I/O even in C++ programs. I just reimplemented
Boost.Rational for Zaiband specifically to get rid of the <</>> operators which
were worth 780K in executable size on MingW32).
* C setjmp/longjmp does horrible things (basically, nothing between a
setjmp/longjmp is allowed to throw exceptions. That includes your floating
point coprocessor, which is capable of throwing exceptions in any language
whatsoever including C.)
* The Curiously Recurring Template Pattern has no C equivalent.
In contrast:
* Classes are glorified structs whose non-static member functions get a first
parameter of their own type for free. Virtual functions go further and spare
you the hassle (but not the binary overhead) of maintaining arrays of function
pointers that depend on the runtype type.
* Exceptions are a glorified goto with even fewer syntactical restrictions than
the real thing: they don't even need to know their target label.
* STL/templates are mostly an overpowered, klunky weak-typechecked macro
system.
Plain Old Data (POD), including POD-structs, *should* do things the C way even
in C++.