[M3devel] operator overloading?

Rodney M. Bates rodney_bates at lcwb.coop
Sun Nov 21 20:52:08 CET 2010


I've been around that block too many times with Ada and C++.  Programmer-
defined overloading (either operator and/or function name) is a semantic
disaster.  It interacts with stuff all over the language, and the complexity
just explodes.  I have spent several years of my life having to learn every
in and out and dark corner of overloading and all its fallout in Ada, both
to implement it and to try to help working programmers cope with it. I can
say with complete confidence that Ada would be half the size/complexity
it is, without it.

Moreover, hard as it is for a compiler writer or language lawyer to understand
it, it is even worse for the everyday programmer.  Again, I can testify that
almost nobody (the above types excepted) comes anywhere close to understanding
the rules.  They don't even want to try.  Their eyes glaze over, and they just
want you to tell them how to code such-and-such so it will compile and call
the function they want it to.  For the future, all they want is restrictive
but simple programming guidelines on things to avoid unconditionally, so they
won't keep getting burned again and again.

C++'s take on overloading is simpler in some respects, more complicated in
others, but overall, quite a bit worse and, I dare say, much poorer-understood
by working programmers.

The upshot is that the (mis)feature of programmer-defined overloading is mostly
used only in degenerate and trivial ways.  This, of course, raises the question
what good is it when: 1) it makes programming more difficult, 2) programmers
avoid most of it anyway, and 3) even so, it results in lots of code that
programmers just barely hope they understand the meaning of what they wrote.
The latter is a *very* big deal in quality of released code.  And I didn't even
mention the added difficulty in implementing the language.

I do realize that function call notation can be a lot harder to read (and write)
than operator notation in a few situations.  I've also been around that block more
times than one, in fact quite recently.

I have many times mused over whether it would be possible to add something that
would give the most important benefits and not be a complete semantic train wreck.
Sometimes I think it could be done a lot better than we have seen, but at best,
it would be a significant semantic complication, even if restricted to operators
only.

In Modula-3, we have a language whose most distinctive characteristic is an
exceptionally high ratio of useful stuff to complexity. AFAIK, there is no other
language that comes close by this criterion.  We need to preserve that.

Rodney Bates


Jay K wrote:
> Is it really so difficult to add operator overloading to the language?
> 
>  From a user's point of view, I know it is very useful in certain 
> situations.
> 
> 
>  - Jay
> 
> 
> 
> 



More information about the M3devel mailing list