[91] in java-interest
Re: Overloading of "+" for string concat
daemon@ATHENA.MIT.EDU (Scott Hudson)
Wed May 17 12:07:53 1995
From: hudson@cc.gatech.edu (Scott Hudson)
Date: Wed, 17 May 1995 10:33:45 -0400 (EDT)
To: java-interest@java.Eng.Sun.COM
> From patl@asimov.lashley.slip.netcom.com Tue May 16 20:57:34 1995
> To: hudson@cc.gatech.edu
> Subject: Re: Overloading of "+" for string concat
>
...
> It looks to me more like an argument for -ALWAYS- fully parenthesizing
> your expressions...
I suppose I should make my point a bit more explicit.
a) "+" really has the wrong precedence to use in this situation. For the
most common uses of string concat (i.e. with implicit invocation of
toString()), one would really like an operator with low precedence,
probably at or below operators "," and "?:".
b) The expression "a + b + c" means the same thing as "a + (b + c)" in
the more common case of addition. The fact that it doesn't in string
concat involving implicit invocation of toString() is non-intuitive.
(You weren't really proposing that I parenthesize an expression like
"a + b + c" were you ?)
c) The error made here is 1) relatively easy to make when one is programming
late at night (I did it by changing "a" to "a+b" in the middle of an
existing println() without thinking much about it), and 2) is relatively
hard to catch (the result still looks like an integer).
d) This is a minor point and all Java programmers will pick up on it pretty
quickly. Its very much akin to the fact that in Pascal you have to put
parens around comparisons joined by logical operators. Its mostly an
annoyance that you quickly get used to. *However*, it may be early enough
in the language that it can still be easily fixed, which is why I brought
it up.
Scott Hudson
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com