Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!aurora!ames!elroy!mahendo!jplgodo!wlbr!voder!tolerant!vsi1!steve From: steve@vsi1.UUCP (Steve Maurer) Newsgroups: comp.lang.c++ Subject: Re: Operator overloading considered harmful Message-ID: <276@vsi1.UUCP> Date: 22 Jan 88 04:12:17 GMT References: <240@vsi1.UUCP> <8180001@nucsrl.UUCP> <2607@calmasd.GE.COM> <265@vsi1.UUCP> <3418@ihlpf.ATT.COM> Reply-To: steve@vsi1.UUCP (Steve Maurer) Organization: Vicom Systems Inc. San Jose, Cal. Lines: 54 } } > Instead, lets take for example... 2 dimentional arrays. } > What shall we define for them? Does '+' mean "combine into a 4 } > dimentional array", "add each seperate element together, depositing } > the results in a 2x array", or "give me the sum total of all these } > numbers" ? Does '*' indicate multiplication? Or does it mean take } > the dot product? What does '/' do?? The answers are quite system } > (or program) dependent. } } Would a function addmatrix(array1, array2) mean "combine into a 4 dimensional } array", "add each separate element together, depositing the results in a 2x } array", or "give me the sum total of all these numbers", etc., etc. } -- NEVIN J. LIBER Your function "addmatrix()" is unlikely to be used in other peoples' programs unless they know about it. The plus "+" operator is used in most programs. No one is forcing me to call "addmatrix()" to add two arbitrary numbers together, I can use what I please. However with plus "+", I had better use it, and also remember your special function for it when I happen to use that class of data. Overloaded functions aren't bad because in general the number of levels of Overloading is kept to a reasonable minimum; with overloaded operators that just isn't the case. Lets assume you have your function 'addmatrix()', but instead some language designer instituted the rule so that it became a non-descriptive function name: "A". Then he said, "A" must be used in infix notation, with a certain predefined precidence and associativity level, no matter what the function is supposed to do. Then he said "A" isn't just yours, "A" will be used by everybody: you must expect name colision. Then he said "A" was in use in already existing code, so when you write your Overloaded routine, you had better get it right or a lot of other people's code may break. Would you still feel as comfortable? > I won't argue the point that the facility can be abused. This merely > points out that software developers must agree on common notation for > an application and document thoroughly the notation used. > Ken Shrum Any facility can be used or abused. But consider the mirror image of your argument: even the worst features in the world can be defended by saying, "If you don't make mistakes, there won't be a problem". That, to me is not a justifiable defense. Mistakes _will_ be made, and it is by by whether language additions help find them, or hide them, that they should be judged. Even if the writers to this newsgroup are general enthusiasts of operloaded operators, I wonder how long they will remain so when they have to start using debuggers on the resulting code. The levels of complexity can be enormous in trying to intuit the meaning of such code, so source level debuggers will probably break down awfully inside of Overloaded Op expressions. This is only a prediction, not anything I have experienced. (I haven't seen a source level debugger for C++ yet, any out there??) Steve Maurer