What a pity that Java not Include Operators overloading,Wake up

J

John W Kennedy

Patricia said:
Who is "we"? I know it does not include me.

C++ suffered from a special problem, being the first very widely used
language to support them. There was a lot of experimentation, with some
of the experiments leading to understanding of what things operator
overloading is *not* good for.


I strongly disagree with the first couple of sentences. The single thing
that operator overloading would do well is allowing more natural-looking
code for non-primitive arithmetic. Using anything other than "+" for
addition is just as unreadable as using "+" for something other than
addition.

It is too late to keep the language designers from bad operator
overloading. String concatenation is not addition, and should not be
represented by "+".

But, quite seriously, why? Group theorists have been utterly at home
with the notion for ages. And what of Boole? Maybe I was exposed to such
ideas at an unusually early age, but, to me, this complaint seems simply
silly. (Please understand that I do /not/ see you as a silly person,
because you aren't, and, besides, "Patricia" was my mother's name.)
There are, God knows, theoretical cases where operator overloading can
be ridiculous. But the idea that string+string cannot mean
concatenation, or that stream>>data and stream<<data cannot signify I/O,
just makes no sense to me. (I have issues with C++, but this is not one
of them.)

I am, of course, assuming a base language in which wild implicit
casting, as in PL/I or most scripting languges, is not present, so that
string+string cannot sensibly mean addition, because strings cannot be
arithmetically added. In a language where they can, things change.

I also grant that it is /much/ more important to get operators into
complex and extended-precision arithmetic than otherwise.
 
J

John W Kennedy

Arne said:
Fortran has had ** forever.

There seems to have been a period where language designers
used a logic like:
if it is in instruction sets then use an operator
if not use a function

Another problem is that exponentiation is traditionally
right-associative (because left-associative exponentiation is unnecessary).
 
P

Patricia Shanahan

John W Kennedy wrote:
....
But, quite seriously, why? Group theorists have been utterly at home
with the notion for ages. And what of Boole? Maybe I was exposed to such
ideas at an unusually early age, but, to me, this complaint seems simply
silly. (Please understand that I do /not/ see you as a silly person,
because you aren't, and, besides, "Patricia" was my mother's name.)
There are, God knows, theoretical cases where operator overloading can
be ridiculous. But the idea that string+string cannot mean
concatenation, or that stream>>data and stream<<data cannot signify I/O,
just makes no sense to me. (I have issues with C++, but this is not one
of them.)
....

They certainly *can* be given those meanings. The question is whether
that is the clearest, most readable approach to those operations.

Patricia
 
M

Mark Thornton

John said:
There are, God knows, theoretical cases where operator overloading can
be ridiculous. But the idea that string+string cannot mean
concatenation, or that stream>>data and stream<<data cannot signify I/O,
just makes no sense to me. (I have issues with C++, but this is not one
of them.)

In Java, mixing String, char, and int values as operands to '+'
frequently produces unexpected results. This also breaks the
associativity that would usually be expected of '+'.

Mark Thornton
 
P

Patricia Shanahan

Mark said:
In Java, mixing String, char, and int values as operands to '+'
frequently produces unexpected results. This also breaks the
associativity that would usually be expected of '+'.

Java float and double addition are not associative, but nobody objects
to using "+" for them.

The big difference between them and the String situation is that float
and double addition are both approximations defined in terms of real
number addition, which is associative.

Patricia
 
J

John W Kennedy

Patricia said:
John W Kennedy wrote:
....
....

They certainly *can* be given those meanings. The question is whether
that is the clearest, most readable approach to those operations.

Well, the "clearest, most readable" approach /might/ be to start
applying unique dingbats up the wazoo to everything -- for openers,
perhaps we should separate integer and floating-point division as "÷"
and "/", as ALGOL 60 did. But that way, madness lies -- let us leave
aside counsels of perfection, and limit ourselves to mere precepts of
readability.

As to the particular case of string concatenation, over the decades I've
used "||", "cat", "+", "&", ".", "##", and null, and had no trouble with
any of them. Note that, of all of them, only "cat" and "##" have no
other well-known meaning. To my mind, and this is true at a more or less
subconscious level, you have to know what type a variable is before you
have any business interpreting what a function /or/ an operator will do
with it. This is just the way my brain works.

--
John W. Kennedy
"There are those who argue that everything breaks even in this old
dump of a world of ours. I suppose these ginks who argue that way hold
that because the rich man gets ice in the summer and the poor man gets
it in the winter things are breaking even for both. Maybe so, but I'll
swear I can't see it that way."
-- The last words of Bat Masterson
 
J

John W Kennedy

Mark said:
In Java, mixing String, char, and int values as operands to '+'
frequently produces unexpected results. This also breaks the
associativity that would usually be expected of '+'.

On computers, "+" isn't even reliably associative when it refers to
numeric addition.
--
John W. Kennedy
"Those in the seat of power oft forget their failings and seek only
the obeisance of others! Thus is bad government born! Hold in your
heart that you and the people are one, human beings all, and good
government shall arise of its own accord! Such is the path of virtue!"
-- Kazuo Koike. "Lone Wolf and Cub: Thirteen Strings" (tr. Dana Lewis)
 
M

Mark Thornton

John said:
On computers, "+" isn't even reliably associative when it refers to
numeric addition.

However as Patricia pointed out, the result is a reasonable
approximation to the exact result (which is associative).
 
T

Tom Anderson

As to the particular case of string concatenation, over the decades I've
used "||", "cat", "+", "&", ".", "##", and null, and had no trouble with
any of them. Note that, of all of them, only "cat" and "##" have no
other well-known meaning.

John, have you seen those little furry things that chase mice and like to
hide in boxes? :)

tom
 
J

John W Kennedy

Tom said:
John, have you seen those little furry things that chase mice and like
to hide in boxes? :)

And go "quack!" -- at least if you're a "Babylon 5" fan.

But there's a big problem with using a Felis catus as a dyadic operator;
it olny payz attentions 2 wun things @ a timez.
--
John W. Kennedy
"The whole modern world has divided itself into Conservatives and
Progressives. The business of Progressives is to go on making mistakes.
The business of the Conservatives is to prevent the mistakes from being
corrected."
-- G. K. Chesterton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top