Personal dialects and C++ overloading

Rick Schaut schaut at cat9.cs.wisc.edu
Thu Feb 15 14:03:44 AEST 1990


Regarding overloading of operators:

In article <926.18:17:58 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
| This Ada (and, by imitation, Fortran 90 and C++) misfeature makes
| program maintenance a nightmare. The problem isn't just that it's a pain
| to locate the routine that adds a GLORP to a FOOBIEBLETCH. The problem
| is that you won't even notice the nonstandard usage until it's too late.

Any compiler that would allow you to apply the "+" operator to a "GLORP"
and a "FOOBIEBLETCH" doesn't conform to the notion of overloading.
Overloading does _not_ come at the expense of strong type checking.  It
_does_, however, allow the programmer to apply the abstract notion of
"addition" to objects for which such an operation makes sense (e.g. sets).

Of course overloading the "+" operator to mean set difference when the two
operands are sets doesn't make much sense in the semantics of any language.
Does passing an array of characters in a parameter that is supposed to be
a pointer to a FILE object make much sense?

| Overloading saves typing time. It has no other advantages. (Is it an
| advantage to be able to code without thinking and make undetectable
| syntax errors?)

Overloading saves having to think about the mechanics of calling the
correct procedure whilst allowing the programmer to think more about the
semantics of the program.  It's not a case of being able to code without
thinking.  Rather, it's a case of being able to code while thinking about
that which is important.

--
Rick (schaut at garfield.cs.wisc.edu)

Peace and Prejudice Don't Mix! (unknown add copy)



More information about the Comp.lang.c mailing list