Personal dialects and C++ overloading
Rick Schaut
schaut at cat19.cs.wisc.edu
Mon Feb 19 09:57:24 AEST 1990
There is a bit of a misunderatanding here which is probably due to my having
jumped in on the middle of a discussion. If so, I apologize and will attempt
to be a bit more lucid.
In article <16334:04:32:49 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
| In article <4301 at daffy.cs.wisc.edu> schaut at cat9.cs.wisc.edu (Rick Schaut) writes:
| > In article <926.18:17:58 at stealth.acf.nyu.edu> brnstnd at stealth.acf.nyu.edu (Dan Bernstein) writes:
| > Any compiler that would allow you to apply the "+" operator to a "GLORP"
| > and a "FOOBIEBLETCH" doesn't conform to the notion of overloading.
|
| Say what? Why not? What if GLORPs and FOOBIEBLETCHen are natural
| candidates for addition? And since when does the compiler decide this
| for you?
If GLORPS and FOOBIEBLETCHen are type compatible (as the programmer has
defined them), then addition should be fine. You seemed to be complaining
that overloading allows you to apply some operator to objects having
incompatible types which, frankly, isn't true.
| Read my comments in another article in this thread about how to make
| overloading readable.
If that's all you were saying I wouldn't have posted a follow-up even though
I don't necessarily agree. Why should we take extra steps to make overloading
more readable (whatever 'readable' means) when we don't for other aspects
of a language? Doing anything to notify the reader that overloading is
being applied in a particular expression seems to defeat the whole purpose
of overloading. If you know the objects to which an overloaded operator is
being applied, why do you need some special flag to tell you there is
overloading? If a compiler can understand overloading, a human ought to
be able to understand it as well.
In any event, you _did_ make the following statement:
| > | 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.
|
| The same would be true if overloading were distinctively marked, by an
| initial character, for example. This would save gratuitous syntax errors
| without being too distracting.
Which you now seem to concede isn't correct. Overloading allows at least
enough advantage that you want to allow it yet flag it in some manner. I
was, primarily, taking issue with the sentence I underlined above.
| Even so, are you sure that vector + vector means addition and not
| concatenation? Or are they character vectors, being used as strings?
I'll grant that ambiguities are a problem, and ambiguities are _usually_
solved through context. However, no language that is in prevalent use
can't be described using a context free grammar, so if the compiler is
smart enough to resolve those ambiguites without a context, a human shouldn't
have any problem whatsoever.
| As many other programmers have pointed out, you should never force
| someone to learn a new language just to read a program.
That's funny. We seem to have very few qualms about the fact that one can't
read a C program without understanding C. Why should new languages be any
different? C++ is _not_ C and isn't intended to be C.
--
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