Most annoying Java gotchas 
Author Message
 Most annoying Java gotchas


Quote:

>Lisp programmers have the same problem; there are at least two defined
>"equality" predicates, just as with Java. One compares strings and
>lists to see if they are the same object (called == in Java, called
>"eq" in Lisp), another compares element by element (called "equals" in
>Java, "equal" in Lisp). I find that Lisp programmers, who are used to
>high level operations, are often surprised when the first fails for
>two different strings or linked lists that contain identical
>elements. But C/C++ programmers expect this, since == in C/C++ returns
>false (0) for two different strings or linked lists, even if they
>contain identical elements.

C test for value equality, however, strings aren't a real data type
in C -- pointers are, so you're not comparing strings for equality,
you're comparing char pointers.

[ C++ allows you to do all sorts of strange stuff. ]

Quote:
>I'm not sure how Java would go about preventing this problem.

Lisp ( and Java ) have the right idea in allowing you to test
for either value or object identity. The only problem is in
not making the distinction clear and obvious in the syntax.

Python, for example, uses "is" for object identity:

Quote:
>>> [1,2,3] = [1,2,3]

SyntaxError: can't assign to literal
Quote:
>>> [1,2,3] == [1,2,3]
1
>>> [1,2,3] is [1,2,3]

0


---|  Computer Systems Engineer          University of {*filter*}ia  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  Box 449 Health Science Center    C{*filter*}tesville,VA 22908  |---
 [ "The grass is always greener, except at t=0" - Stan Kelly-Bootle ]



Tue, 06 Oct 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. IFC Gotchas.

2. wxPython gotchas

3. Modul gotchas:)

4. Win32Com: VB5 COM server gotchas

5. FORTRAN "gotchas", and how to aviod them

6. REAL [annoying] bug

7. Annoying Freezing Bug

8. very annoying post

9. Hope I'm not getting Annoying But

10. CW2.0 - bug that is REALLY annoying

11. Annoying Little Problem

12. Annoying problem

 

 
Powered by phpBB® Forum Software