Power (Re: all those :-)

Ned Nowotny ned at ghostwheel.UUCP
Sat Feb 6 04:02:52 AEST 1988


In article <744 at PT.CS.CMU.EDU> edw at IUS1.CS.CMU.EDU (Eddie Wyatt) writes:
>In article <3521 at ihlpf.ATT.COM>, nevin1 at ihlpf.ATT.COM (00704a-Liber) writes:
>> 
>> Then where is the operator for string concatenation, and square root, and
>> everything other binary function that is used by C programmers? 
>
>Why not? why not have an extendable language, where the user is free to 
>define his own infix operators?  Is it that outragous?  
>THIS IS JUST HYPOTHETICAL - I"M NOT SERIOUSLY APPROSING THIS!
>

In some sense, C++ has this (mis-)feature -- operator and function overloading.

Conceptually, overloading is very nice.  It allows programmers to declare new
data types and operations on them using standard notations.  For instance, a
complex double data type can be defined and then operations can be defined on
these data types using the "+", "-", etc. operators.

Unfortunately, not all programmers seem to agree on what constitutes a good
use of operator overloading.  I have seen code which overloaded "+" and "-"
to add and remove, respectively, an object from a set of objects.  The result
was an unforeseen side effect to some global data structure using these
operators on the given data type and code similar to the following:

do_something();
A + B;
do_something_else();

That's right.  It looks like a useless expression, but its not.  Its just a
headache for the next programmer.  Function overloading can result in similar,
but less painful abuses.

Of course, it can be argued that the misuse of a feature by a programmer is
no excuse for blaming the feature.  However, functional notation is perfectly
adequate for programmer defined operations and somewhat easier to track down.
Infix notation is better left to a language implementor.  At least then,
everyone who uses the language knows what a given expression means, even
when it doesn't mean the right thing.

-- 

Ned Nowotny (ned at ghostwheel.aca.mcc.com.UUCP)



More information about the Comp.lang.c mailing list