[539] in java-interest
Re: BigInteger class out there?
daemon@ATHENA.MIT.EDU (Patrick Doane)
Thu Jun 29 11:14:38 1995
Date: Thu, 29 Jun 1995 10:58:08 -0400
To: java-interest@java.Eng.Sun.COM
From: pdoane@pcnet.com (Patrick Doane)
> |>Which brings us to my question: why no operator overloading in Java?
> |
> |My understanding was that it was a value/complexity tradeoff but either
> |Arthur van Hoff or James Gosling can answer this question more completely.
>
> Personally I'm not too keen on operator overloading; while it's useful
> for extending the numeric types it makes people want to build things
> like C++'s iostreams. Is the benefit really worth the cost?
>
> (I'm only half joking.)
>
>For the other half: I like the operator-overloading part of iostreams.
>printf formatting was fine too, expressively, but it was dangerous and
>slow. I find the Pascal/Java solution simply dull beneath description.
>
>But, yes, operator-overloading does present temptations to the unwary.
>What are the other expenses? It seems like a trivial addition to the
>compiler; as people on comp.lang.c++ point out endlessly, it is
>semantic sugar.
>
Besides "looking better", I've found that some operator overloading also
helps with code maintainability. Since I'm dealing with tight memory
constraints, I often need to change the amount of bits a number will
occupy. Almost all objects in the code need to be persistent, and its very
easy to write code like this:
class foo {
char x;
short y;
long z;
};
and write them out like this:
s << x;
s << y;
s << z;
instead of:
s.writeChar(x);
s.writeShort(y);
s.writeLong(z);
Anytime I want to make a change of variable type in foo, I have to redo
the read/write operators.
I agree that operator-overloading is not worth the cost. This is especially
true when, at least in C++, you often can't get operator-overloading to
generate the code you want to do anyways (like with the + operator).
The only benefit I've found to template functionality has been for speed
and memory critical aspects of a program. I've come to the conclusion that
they are next to worthless as array containers. The overhead of the
additional code necessary to access these arrays is hardly worth the speed
and memory savings. They became a nice feature when I was writing buffered
i/o code and wanted to have highly optimized routines for reading and
writing 8, 16, or 32 bit values without having to write each function
independently.
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com