July 21, 2014
A rule I learned from writing Java is that if you implement equality, you must also implement hashing, and if you implelement hashing you must implement equality. I believe this is actually a general truth of programming in any language, and now D has the right kind of semantics.

On an off topic note, I noticed your signature, H.S. Teoh.

> "640K ought to be enough" -- Bill G., 1984.

That quote is well known for being fabricated. The year varies wildly. There's no evidence of Bill ever saying it which isn't someone saying, "Trust me, I heard him say it once."
July 21, 2014
On Mon, Jul 21, 2014 at 06:28:48PM +0000, w0rp via Digitalmars-d wrote:
> A rule I learned from writing Java is that if you implement equality, you must also implement hashing, and if you implelement hashing you must implement equality. I believe this is actually a general truth of programming in any language, and now D has the right kind of semantics.

This should generally be obvious, since the AA has to hash the object, then distinguish between objects with the same hash by comparing them with some kind of comparison operator. Obviously, if the hash function is inconsistent with this comparison operator, then you're going to get inconsistent behaviour out of the AA.

Now, one *could* argue that in some cases, you could implement custom equality but use the default hash function, because you know that your custom equality is consistent with it, but I'd say this is a risky assumption because if it turns out that it's actually *not* consistent, then you end up with a very hard-to-trace bug. So in general, requiring that either you use default equality and hash, or redefine both, seems to be the most logical approach.


> On an off topic note, I noticed your signature, H.S. Teoh.
> 
> >"640K ought to be enough" -- Bill G., 1984.
> 
> That quote is well known for being fabricated. The year varies wildly. There's no evidence of Bill ever saying it which isn't someone saying, "Trust me, I heard him say it once."

Funny, your reply prompted me to search for the attribution, and I came across this:

	http://imranontech.com/2007/02/20/did-bill-gates-say-the-640k-line/

Of course, most of my quotes are meant to be humorous in some way, so they shouldn't be taken 100% seriously. So I just changed it to:

	"640K ought to be enough" -- Bill G. (allegedly), 1984.
	"The Internet is not a primary goal for PC usage" -- Bill G.,
	1995.
	"Linux has no impact on Microsoft's strategy" -- Bill G., 1999.

;-)


T

-- 
Computers are like a jungle: they have monitor lizards, rams, mice, c-moss, binary trees... and bugs.
July 21, 2014
On 2014-07-21 20:17, H. S. Teoh via Digitalmars-d wrote:

> I'm inclined to say, file a regression bug. If opCmp is defined but
> opEquals isn't, the compiler should auto-generate opEquals (as
> opCmp(...)==0).  Requiring the user to implement a separate opEquals
> when opCmp is already there is nonsensical, and opens the door to stupid
> bugs due to increased boilerplate. (Of course, if the user also defines
> opEquals manually, that's fine. But if he doesn't, the compiler should
> do the Right Thing(tm).)

Filed as https://issues.dlang.org/show_bug.cgi?id=13179

-- 
/Jacob Carlborg
1 2
Next ›   Last »