[1091] in java-interest

home help back first fref pref prev next nref lref last post

Re: Operator underloading (was: overloading of operators)

daemon@ATHENA.MIT.EDU (Kevin Krom)
Fri Aug 18 13:50:25 1995

Date: Fri, 18 Aug 1995 10:23:06 +0500
From: krom@cgi.com (Kevin Krom)
To: java-interest@java.sun.com
Cc: Philip.Gladstone@onsett.com

Philip Gladstone writes:
> I propose that we do some operator-underloading. The + sign is already used
> for integers and floating point. This leads to endless confusion, so I
> propose that + is reserved only for integers, and that a new operator
> ("floatAdd" - if you like smalltalk syntax) or a class member function be
> defined to add floats. 
> 
> This approach has some useful advantages - the comparison operator <
> would be replaced by "floatLessThan", and we could eliminate the 
> floating point <= operator entirely (as floating point numbers are
> very rarely equal to other floating point numbers).
> 
> The readability of the language would improve - you wouldn't have to
> worry about whether   10/4 is actually 2 or 2.5

I hope I am not wrong in taking this as tongue-in-cheek...

Why not use and extend the Pascal notation?  Pascal already has "div" and
"mod" as integer versions of the "/" and "%" operators.

*** SARCHASM MODE ON ***

But to the original point, if we're going to start "underloading" operators,
then why not just get rid of them altogether?  Why make one type have a
different look and feel than the others.  Then we can get simple expressions:

	int a, b, c, d;
        float e, f;

	f = ((float) (a.Add(b)).Multiply(e.Divide((float) (c.Add(d))))

I think that the above version is much more readable than this ambiguous and
confusing form:

	f = (a + b) * (e / (c + d));

*** SARCHASM MODE OFF ***

Flame away...

--
Kevin M. Krom, Software Engineer         Phone:  (412) 642-6900 x242
Carnegie Group, Inc.                     Fax:    (412) 642-6906
5 PPG Place, Pittsburgh PA 15222         Email:  krom@cgi.com
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post