[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT: Why is C so popular?



On Wed, Aug 27, 2003 at 12:19:18PM -0500, Ron Johnson wrote:
} On Wed, 2003-08-27 at 09:53, Gregory Seidman wrote:
} > On Wed, Aug 27, 2003 at 12:43:55PM +0200, Frank Gevaerts wrote:
} > } On Wed, Aug 27, 2003 at 01:11:08AM -0500, Alex Malinovich wrote:
} > [...]
} > } First convince me that object oriented programming results in
} > } maintainable and debuggable code, then convince me that C++ is a good
} > } implementation of OO, and then I might consider C++ instead of C. (I
} > } know not all the features of C++ are related to OO, but OO seems to be
} > } the main selling point of C++ vs C)
} > 
} > OO was, at one time, the primary purpose of C++ extending C. It no longer
} > is. C++ is a tolerable, if annoying, OO language but it is hardly an
} > exemplary one. It does, however, have templating and the standard library
} > (formerly the Standard Template Library, a.k.a. STL). This allows some very
} > powerful and elegant code, and provides an astoundingly flexible library of
} > common data structures and algorithms. The Boost project is working on
} > creating an even more comprehensive library (for possible inclusion into
} > the next C++ standard). It is generic programming, enabled by C++ templates
} > and OO, that give C++ it's value.
} > 
} > As an example of how C tries and fails to do the same sort of thing,
} > consider the standard C qsort() function. The qsort() function is generic,
} > but lacks any sort of type safety. The C++ templated sort function provides
} > the same generic sort function, but with type safety.
} 
} If you want a C-like OO language with type safety, why not use Java?

Let me clarify. What makes C++ powerful is that one can write typesafe code
that does not depend on the type being handled. Let me run that by you
again in an example. The C++ standard library's vector class allows me to
hold objects of some particular type. The source code implementing the
vector class does not care what type, but upon compilation I will be
informed if I am trying to store something of the wrong type in it.

The emphasis here is on "upon compilation." I don't get an exception at
runtime if I happen to follow a code path that results in the wrong thing
being stored (and retrieved, and cast), I get a compilation error even if
it never occurs to me to test that particular code path. It's called static
analysis, and it's damned nice when your compiler does it for you.

Java doesn't cut it. You can and often do have type errors which cannot be
discovered except by extensive runtime testing. Relying on testing alone is
a losing proposition, since the number of code paths in a program of any
reasonable size is simply intractably large.

Now, the next version of Java is expected to have templated collection
classes and such, which will give it some of that power. It will not,
however, allow templated methods (AFAIK). This is rather limiting.

Let me make it clear that I am not claiming that Java is useless, or even
worse than C++. There are purposes to which it is far more suited.
Nonetheless, I'd choose to write any user application (GUI or CLI) of any
complexity with C++, and most varieties of server as well.

} Ron Johnson, Jr. ron.l.johnson@cox.net
--Greg



Reply to: