What is your evaluation of the proposal?
+0.5. I think the protocol is poorly named and documented.
The thing is, there are lots of kinds of identity. The thing I think we're talking about here is "record identity" - i.e. that two objects may have different values and not be substitutable, but conceptually both talk about the same element of data, like the primary-key in a database. Another kind of identity is object/reference identity.
The name "Identifiable" doesn't really make clear what kind of identity is being talked about, and the default implementation for classes confuses the two concepts. Even for classes, they might not be the same.
Take CoreData, for example: the kind of identity we are talking about here is represented by the NSManagedObject.objectID
property (see the docs for NSManagedObjectID
). Within an NSManagedObjectContext, there is only one reference to a record, so the two concepts are equivalent, but across contexts, you will see different instances, with different memory addresses, referring to the same record and sharing NSManagedObjectID
values. The MOID is used for exactly the kind of diffing described in this proposal.
For this reason, I don't think the ===
operator needs to consider these values, and I would remove the default implementation for classes. I think that would be confusing, and after all, it isn't much work to write x.id == y.id
.
Some alternative names: Record
, IdentifiableRecord
... something like that, perhaps.
Is the problem being addressed significant enough to warrant a change to Swift?
Does this proposal fit well with the feel and direction of Swift?
Myeh. Kinda. You see this concept quite often in model code, which you often want to share across platforms, so I can see the benefit to sinking it to a lower level. I'm not sure if it should be in the standard library or another library.
If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
See discussion above about CoreData.
How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
Quick reading.
EDIT: Oh, and just a suggestion - I think it wouldn't hurt if the Apple folks asked the CoreData team for their input on this (if they didn't already). It seems natural that we would want NSManagedObject
to conform to this protocol. I'm kind of surprised that it doesn't already conform to the thing that exists in SwiftUI.