>>21
Magic instance variable
I don't see the appeal of this. I'd probably even prefer like Visual Basic
(ugh), which has
= and
Is.
The way it works in C♯ is as follows:
== on reference types tests reference equality by default, but can be overloaded.
== on value types generates an error unless the struct overloads
==. There's also the
Object.Equals() method, which every object (reference or value type) has. For reference types it tests reference equality; for value types is tests value equality. In both cases it can be overridden.
There's also two ways of making sure you're testing reference equality: cast one of the objects to
object or use
object.ReferenceEquals, which is a static method.
Oddly
string isn't actually a value type, despite being immutable, it just overloads
== and
!= and overrides
Equals. Using the operators will probably be more efficient, since both arguments are known to be strings at compile-time.
In conclusion, C# somehow managed to be more screwed up than Sepples. On second thought, though, Sepples has `references' as well as pointers, so:
A *a = new A(), *b = new A(), &ra = *a, &rb = *b;
a == b; // probably false (reference equality)
ra == rb; // value equality (A's operator ==())
which may not be obvious at first.
-------------------------------
I'm not a fan of operator overloading to the extent that Sepples does it, but
== and
!= is common sense (arithmetic operators can help clarify code too). I'm also mostly fine with Haskell's mass of weird operators like
f <^(+.+)^> g since they at least only have one meaning, whereas Sepples turns bit shifts into I/O.