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

A

Andrea Francia

Lew said:
Andrea Francia



Quoting yourself does not provide evidence of my opinion.

Sorry, I misunderstood your words because of fast reading, forgot that
and forgive me.
Apparently.

Please tell me what I think then.
Lew:



I never said you said that. I was explaining my remarks so that you
would see that I was not discussing overloads of operators.

Ok, now I understand.
 
T

Tom Anderson

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

Why isn't it? What do you get if you add two strings, then?

tom
 
P

Patricia Shanahan

Tom said:
Why isn't it? What do you get if you add two strings, then?

What do you get if you multiply two strings? Or take the square root of
one?

I don't think addition is a good metaphor for a non-commutative
operation such as string concatenation.

Patricia
 
M

Mark Thornton

Tom said:
Why isn't it? What do you get if you add two strings, then?

tom

"25" + "75" ==> "100"

The Java '+' operator doesn't add two strings, it concatenates them.
 
T

Tom Anderson

What do you get if you multiply two strings? Or take the square root of
one?

I get very confused. But then i don't try to do those things, so it
doesn't matter much.
I don't think addition is a good metaphor for a non-commutative
operation such as string concatenation.

Fair enough. I differ from you on this - i agree that adding two strings
does not look a lot like adding two numbers, in particular because it's
not commutative (although i note that this doesn't stop mathematicians of
a certain bent adding ordinal numbers). But adding numbers is just a
particular case of the informal, natural idea of putting two things
together; i think + is a perfectly good symbol for that, and i think
string concatenation is another particular case of it, and so + is a good
symbol for string concatenation.

Having said that, i'm not zealous about it. It's more that i think + is
a member of the set of acceptable symbols for string concatenation, rather
than the only such symbol.

If not +, what symbol would you use for string concatenation?

As far as i can tell, in mathematics, strings concatenation is written by
putting the two variables together, as in multiplication - so the
concatenation of two strings a and b is ab. Not a lot of use. However,
strings under concatenation constitute a monoid, and the general symbol
for the operation of a monoid is *. How would you feel about that? :)

tom
 
T

Tom Anderson

"25" + "75" ==> "100"

Incorrect.

Indeed, no more correct than me writing:

25 + 75 ==> 20

Because that's what it works out it in addition modulo 80. They're
different mathematical structures, and the way one behaves has no bearing
on the other.
The Java '+' operator doesn't add two strings, it concatenates them.

For strings, as far as i'm concerned, they're the same thing.

tom
 
P

Patricia Shanahan

Tom said:
I get very confused. But then i don't try to do those things, so it
doesn't matter much.


Fair enough. I differ from you on this - i agree that adding two strings
does not look a lot like adding two numbers, in particular because it's
not commutative (although i note that this doesn't stop mathematicians
of a certain bent adding ordinal numbers). But adding numbers is just a
particular case of the informal, natural idea of putting two things
together; i think + is a perfectly good symbol for that, and i think
string concatenation is another particular case of it, and so + is a
good symbol for string concatenation.
....

Isn't this the core of the issue of over-use of operator overloading? In
C++, a habit developed of using e.g. "+" for anything that might be
considered to be putting two things together in some sense, and it got
completely out of control.

I would prefer to keep "+" strictly for arithmetic addition, but have it
for all arithmetic types, including user defined ones.

Patricia
 
M

Mark Thornton

Joshua said:
"The end of the world" + "The beginning of time" = ?

An arithmetic error of course! ;-)
I agree with Patricia that '+' should have been kept solely for numbers.
 
C

Chronic Philharmonic

Patricia Shanahan said:
[...]

Isn't this the core of the issue of over-use of operator overloading? In
C++, a habit developed of using e.g. "+" for anything that might be
considered to be putting two things together in some sense, and it got
completely out of control.

C++ operator overloading did get out of control for a while there. I think
today, operator overloading has a certain stigma about it, rather like
"goto". There are a few places where it obviously makes sense and improves
readability; the rest of the time, it is probably best to avoid it.
I would prefer to keep "+" strictly for arithmetic addition, but have it
for all arithmetic types, including user defined ones.

The use of "+" for string concatenation dates all the way back to BASIC in
the mid 1970s. It has become a common metaphor and a programming legacy; I
doubt that it confuses anyone. The "+" operator does have some meaning
outside of purely mathematical disciplines.

While we're on the subject of operators, isn't it odd that Java and C++
don't have operators for roots and exponents? At least BASIC had "^" for
exponentiation (e.g., x^y), which of course, could also be used for roots
when y < 1, so that saying 2^0.5 yields the square root of two.
 
A

Arne Vajhøj

Chronic said:
While we're on the subject of operators, isn't it odd that Java and C++
don't have operators for roots and exponents? At least BASIC had "^" for
exponentiation (e.g., x^y), which of course, could also be used for roots
when y < 1, so that saying 2^0.5 yields the square root of two.

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

Arne
 
T

Tom Anderson

...

Isn't this the core of the issue of over-use of operator overloading? In
C++, a habit developed of using e.g. "+" for anything that might be
considered to be putting two things together in some sense, and it got
completely out of control.

Is that what happened? I'm not very familiar with the saga of operattor
overloading in C++; i know about things like >>/<< and the madness of
overloading . and =, but i hadn't heard about abuses of +. I know that in
C#, += is abused to represent the add method of certain collections, which
i would agree is bad and wrong.
I would prefer to keep "+" strictly for arithmetic addition, but have it
for all arithmetic types, including user defined ones.

What would you use for string concatenation, then?

tom
 
M

Mark Thornton

Tom said:
Is that what happened? I'm not very familiar with the saga of operattor
overloading in C++; i know about things like >>/<< and the madness of
overloading . and =, but i hadn't heard about abuses of +. I know that
in C#, += is abused to represent the add method of certain collections,
which i would agree is bad and wrong.


What would you use for string concatenation, then?

tom

Perhaps '#'
 
A

Andreas Leitgeb

Mark Thornton said:
An arithmetic error of course! ;-)

rather:
"The end of the worldThe beginning of time" is not
an lvalue and ? not even an rvalue :)
I agree with Patricia that '+' should have been kept solely for numbers.

I agree on the numbers, but not on the "only": adding strings is ok,
too, imo.
 
O

Owen Jacobson

  In C and C++, the expression ("a" "b") indeed
  represents the string »ab«.

This is, however, only true of string _literals_, not of arbitrary
char * or std::string expressions. Detecting (and eliding) two
adjacent " tokens from a larger string literal is pretty easy. :)

-o
 
J

John W Kennedy

Lew said:
Precisely.

Regardless, the "joke" (so-called) held a point that needed to be
addressed, because the type of thinking it satirized is extant in the
real world. This led in turn to a valid point that could be made even
if the triggering comment was meant to be funny. Stating that the
original remark was a joke in no wise reduces (or enhances) the validity
or applicability of the response.

Back when I lived in the mainframe world, we sometimes had system
software (e.g., compilers and their RTLs) over a decade out of date for
no cause but sheer, paralyzing fear in middle management.




--
John W. Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
 

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,009
Latest member
GidgetGamb

Latest Threads

Top