3 ms·
How is this superior to the standard relational algebra method of using immutable keys associated with mutable attributes? The fun example is ZIP CODE for hous
by taeric 6y ago
How is this superior to the standard relational algebra method of using immutable keys associated with mutable attributes?
The fun example is ZIP CODE for houses. Since one house can have multiple values, it makes sense that the house had another key representation. And that using equality based on what is ultimately a mutable attribute just doesn't really make sense.
Even your "aardvark" example fails if you for some reason also reference it as an "Orycteropus afer". Right?
Now, if you expose that at all equal spots, it makes sense. Sorta "a.equals(b, by(get name))". Or as common lisp does it in most spots, ":key #'person-name". :)
- kazinator 6y agoFirstly, whatever problems you anticipate with the aardvark also afflict the Java way of defining a two-place equal method, with the hashing burden and all. Ultimately, what do these operations do? They bottom out on some built-in data types like strings and numbers: stuff made of bits. Equality substitution says: please, just produce the representative bits, and let the regular equality deal with it, instead of keeping those bits encapsulated and trying to implement hashing, equality and inequality yourself. Imagine the account object implemented in a Java-like way. All that the binary equal method is going to do is compare the darned user-id strings. The hash method will hash the string. The less comparison method will compare the strings. At the end of all that, due to the encapsulation, you still don't have the useful property that a and "aardvark" are equal: the equal method is only called for other account objects. Equality substitution doesn't enforce the immutability of keys. That's up to the programmer and almost always a good idea. In a small "throwaway" program, if someone finds some clever use for a mutating equality substitute, I mean, more power to them. (That program probably won't be, or shouldn't be, using hash tables, because the documentation explicitly states that hash table behavior becomes unspecified if objects are inserted into it whose equality substitutes mutate.) The leeway in the system allows an object to come to life without an equality substitute value, which is then lazily calculated by the equal method and cached. Since that happens on the first call, it doesn't look like a mutation from the equality point of view. Objects can have more than one key. Objects of the same kind can be considered equal in more than one way. Well, there is only one equal function: you get to pick one of those equalities to be the one that equal uses. I thought about ways to work-in multiple equality relations, but that's a work in progress.
- taeric 6y agoMakes sense. I particularly like the "more power to them". :)
- kazinator 6y agoJust not, like, power over people or world economies or anything of the sort. :)
- Nullabillity 6y ago> you still don't have the useful property that a and "aardvark" are equal That sounds more like a footgun to me. The blogpost slug "aardvark" and the username "aardvark" aren't equivalent. The type carries crucial semantic intent.
- kazinator 6y agoThere can easily be a form of equality substitution whereby the types of the original objects remain relevant for the purposes of the comparison. So that is to say, equal still demands some sort of type match on the original objects, and if that is satisfied, then it proceeds with the equality subs. Just, not in my language, thanks. Problem is, how exact of a match do we require? And the exact match is out of the question, too, since it ignores inheritance. If the blogpost slug is derived from username by inheritance, I might want them to be comparable. Thus left has to be a subtype of right, or vice versa. However, a key property of my object system is that it does not require inheritance for substitutability, you see. The programmer expectation is that they can write some new type from scratch which just has the right properties and methods to be used wherever some existing type is applicable, without inheriting from any common base. And "right properties and methods" includes the equal method for equality substitution.