Mail Archives: djgpp/1999/08/15/10:20:43
C++ gives you the ability to write object oriented programs. This
means that you can treat your data in a way that some consider more
natural and easy to understand. It also gives a mechanism by which
abstraction can occur, that is, the inner workings of a certain
mechanism can become hidden, revealing only the interface. The
advantages of this are generally touted as being:
- Code implementing a particular mechanism (say, a linked list) can be
re-written, without modifying any other code (even that which uses
linked lists) so long as the interface remains the same and
- There is less chance of programming errors occurring, as it is
easier to work with a simplified interface than to have to try to
understand the entire workings of a mechanism. The ability to tweak
low-level parts can also be more tempting to someone programming in
straight C.
That having been said, it is possible (with good programming) to
achieve a similar effect using C. C++ does however provide mechanisms
to prevent the so-called "low-level tweaking"; it also provides a more
natural way to represent interfaces.
C++ also provides other novelties which make certain tasks easier than
they would be if programming in C. For example, inheritance, where one
mechanism (or ADT, for "Abstract data type") can inherit "properties"
(functions and fields) from others. Also, the ability to treat base
and derived classes (ADT implementations) as if they were the same,
and thus to perform a standard operation on them as if the exact type
was already known. The appropriate interface is determined at
run-time. This can be achived in C, but only through programmer
intervention.
The main benefit, though, of C++ is I believe its support of
templates. This gives the ability to write, for instance, a linked
list class which can work with any data type (int, float, user
defined). What is essentially the same code does not have to be
re-written over and over again.
Incidentally, for general programming, there is no advantage to using
C over C++. Most C programs are valid (and functionally equivalent)
C++ programs anyway (in fact, the only ones I've seen that were not
were obscure and created entirely for the purpose of demonstrating
that a C program when compiled as C++ may not always behave exactly
the same).
C does remain popular however; it is generally considered easier to
learn, less complicated, and there is also a large base of existing
programs written in it.
Davin.
On Sat, 14 Aug 1999 21:22:35 -0700, "Al Morgan" <muaddib AT proaxis DOT com>
wrote:
>What are the advantages to using C++, as opposed to C, and vice versa?
>
>Thanks in advance,
> Al [muaddib AT proaxis DOT com]
>
>
__________________________________________________________
*** davmac - sharkin'!! davmac AT iname DOT com ***
my programming page: http://yoyo.cc.monash.edu.au/~davmac/
- Raw text -