Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Hashtable

Reply
Thread Tools

Hashtable

 
 
Oliver Wong
Guest
Posts: n/a
 
      01-25-2006

"Thomas Hawtin" <(E-Mail Removed)> wrote in message
news:43d7a4ce$0$1479$(E-Mail Removed)...
> Roedy Green wrote:
>> On Tue, 24 Jan 2006 23:14:16 +0000, Thomas Hawtin
>> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
>> who said :
>>
>>> Not necessarily a problem. + and - are used as both unary and binary
>>> operators.

>>
>> Even you could, my whole reason to avoid + is so that you don't use
>> the same symbol for two unrelated purposes even if the compiler can
>> figure it out.

>
> It is traditional in C-style languages.
>
> & - reference and and
> * - dereference and multiply
> + - addition and string concatenation (a non-commutative operation)
> . - instance qualifier and decimal point
> ) - bracketing, indicating a function and end of if/while/for
> expression.
> > - greater than and end of generic type list
> >> - read, shift right and end of two generic type lists
> >>> - logical shift right and end of three generic type lists

>
> Also % and ^ in Microsoft extensions to C++.


It is occasionally pointed out that although Java claims operator
overloading is bad (which is one of the reason Java doesn't allow operator
overloading), it's somewhat hypocritical that Java overloads the + operator
to mean both numerical addition and string concatenation.

So coming up with a new operator for string concatenation might be seen
as a way to fix this inconsistency.

- Oliver


 
Reply With Quote
 
 
 
 
Thomas Hawtin
Guest
Posts: n/a
 
      01-25-2006
Roedy Green wrote:
> On Tue, 24 Jan 2006 23:14:16 +0000, Thomas Hawtin
> <(E-Mail Removed)> wrote, quoted or indirectly quoted someone
> who said :
>
>> Not necessarily a problem. + and - are used as both unary and binary
>> operators.

>
> Even you could, my whole reason to avoid + is so that you don't use
> the same symbol for two unrelated purposes even if the compiler can
> figure it out.


It is traditional in C-style languages.

& - reference and and
* - dereference and multiply
+ - addition and string concatenation (a non-commutative operation)
. - instance qualifier and decimal point
) - bracketing, indicating a function and end of if/while/for
expression.
> - greater than and end of generic type list
>> - read, shift right and end of two generic type lists
>>> - logical shift right and end of three generic type lists


Also % and ^ in Microsoft extensions to C++.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
 
 
 
tuurbo46@yahoo.co.uk
Guest
Posts: n/a
 
      01-25-2006

Hi

Thanks for your advice.

Im not next to the enviroment right now. I will get back to you
tomorrow.

Thanks again.

 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-25-2006
On Wed, 25 Jan 2006 16:35:38 GMT, "Oliver Wong" <(E-Mail Removed)>
wrote, quoted or indirectly quoted someone who said :

>
> So coming up with a new operator for string concatenation might be seen
>as a way to fix this inconsistency


I'm fine with leave + the same in the canonical text files. I just
want to have an IDE display it differently, even if just a different
colour + for addition and concatenation to make errors stand out. Java
gets "confused" if you don't use enough ().
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-25-2006
Roedy Green <(E-Mail Removed) > writes:
>I'm fine with leave + the same in the canonical text files. I just
>want to have an IDE display it differently, even if just a different
>colour + for addition and concatenation to make errors stand out. Java
>gets "confused" if you don't use enough ().


I a sense, there is another overload.

Some programmers (ab)use the "+" operator to convert
to java.lang.String, as in:

"" + 2

instead of

java.lang.String.valueOf( 2 )

So "+" could mean:

- numerical addition,
- string concatenation, or
- conversion to string.

However, I have no problem with all this. Human natural
languages tend to overload nearly every word with different
meanings, and polymorphism in OOP also might be considered as
some kind of "overloading" of a name with many ("poly")
implementations ("morphs").

So if it is used in natural languages and in OOP, why
should it be a problem when used for some operators?

 
Reply With Quote
 
Stefan Ram
Guest
Posts: n/a
 
      01-25-2006
http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram) writes:
>"" + 2


There is also similar other bad way, to convert to String, namely,

"".valueOf( 2 )

 
Reply With Quote
 
zero
Guest
Posts: n/a
 
      01-25-2006
(E-Mail Removed)-berlin.de (Stefan Ram) wrote in news:conversion-20060126000436
@ram.dialup.fu-berlin.de:

>
> There is also similar other bad way, to convert to String, namely,
>
> "".valueOf( 2 )
>


This is a side-effect of static factory methods. Perhaps it could be
overcome if language designers only allowed static methods to be called
with the ClassName.methodName() syntax, and not objectName.methodName().

Btw, I don't see anyone who knows a little about Java using the syntax you
mentioned, even if they are unaware of the performance hit.
String.valueOf() is more natural than "".valueOf().
 
Reply With Quote
 
Andrew McDonagh
Guest
Posts: n/a
 
      01-26-2006
zero wrote:
> (E-Mail Removed)-berlin.de (Stefan Ram) wrote in news:conversion-20060126000436
> @ram.dialup.fu-berlin.de:
>
>
>> There is also similar other bad way, to convert to String, namely,
>>
>>"".valueOf( 2 )
>>

>
>
> This is a side-effect of static factory methods. Perhaps it could be
> overcome if language designers only allowed static methods to be called
> with the ClassName.methodName() syntax, and not objectName.methodName().
>
> Btw, I don't see anyone who knows a little about Java using the syntax you
> mentioned, even if they are unaware of the performance hit.
> String.valueOf() is more natural than "".valueOf().


I had a terrible time trying to stop some of our devs doing "" + 2 or
"".valueof(2) most don't see the problem

and only see that its less keyboard typing...

like the thread on variable naming, where someone replied that I must
lilke keyboarding typing because I'd rather use a meaningful english
sentence, rather than negate the result of another method..

as in...


if( noMoreElements()

instead of..

if (! hasMoreElements())...



Typing away atthe keyboard is irrelvant... code and design clarity are
much more important.

Andrew


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      01-26-2006
On 25 Jan 2006 23:00:08 GMT, (E-Mail Removed)-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

>
> So if it is used in natural languages and in OOP, why
> should it be a problem when used for some operators?


I gave a reading comprehension test on this + ambiguity matter to room
full of high powered Java coders at a software conference. Most
failed.

See http://mindprod.com/jgloss/gotchas.html#CONCATENATION

--
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.
 
Reply With Quote
 
Oliver Wong
Guest
Posts: n/a
 
      01-26-2006

"Stefan Ram" <(E-Mail Removed)-berlin.de> wrote in message
news:(E-Mail Removed)-berlin.de...
> Roedy Green <(E-Mail Removed) > writes:
>>I'm fine with leave + the same in the canonical text files. I just
>>want to have an IDE display it differently, even if just a different
>>colour + for addition and concatenation to make errors stand out. Java
>>gets "confused" if you don't use enough ().

>
> I a sense, there is another overload.
>
> Some programmers (ab)use the "+" operator to convert
> to java.lang.String, as in:
>
> "" + 2
>
> instead of
>
> java.lang.String.valueOf( 2 )
>
> So "+" could mean:
>
> - numerical addition,
> - string concatenation, or
> - conversion to string.


At the bytecode level, + is very heavily overloaded. It could be integer
addition, or long addition, or double precision floating point addition, or
single precision floating poitn addition. At the "Java" level, we usually
gloss over that, and just consider all those operations to be the same (even
though the algorithm could vary wildly, for example between integral
addition and floating point addition).

The "string concatenation" and "conversion to string" isn't two
different overloaded operations. Actually, when you do the string
concatenation, string conversion always occurs. So for example, the express
"Hello " + "world" converts its arguments to strings (which is trivial since
they are both already strings), and then does the concatenation.

>
> However, I have no problem with all this. Human natural
> languages tend to overload nearly every word with different
> meanings, and polymorphism in OOP also might be considered as
> some kind of "overloading" of a name with many ("poly")
> implementations ("morphs").
>
> So if it is used in natural languages and in OOP, why
> should it be a problem when used for some operators?


1 + 1 + " foo" == "2 foo"
"foo " + 1 + 1 == "foo 11"

If you follow the rule of least astonishment, the above behaviour
shouldn't happen, because most people would be surprised by it. Why are they
surprised? Because they are confusing when + is performing numerical
addition and when it is performing string concatenation.

I'm not saying ALL operator overloading is bad; I'm just saying that
overloading an operator to perform both numerical addition and string
concatenation can lead to surprising behaviour.

- Oliver



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
Problem with hashTable Guillermo Perl 1 03-04-2004 12:43 PM
Type Hashtable not defined diya ASP .Net 1 10-31-2003 06:59 PM
Get Hashtable Object Directly John E ASP .Net 1 10-08-2003 12:40 PM
vbc compilation fails when using Hashtable Jonathan Wolfson ASP .Net 1 06-27-2003 04:40 PM



Advertisments