> On Aug 1, 2016, at 19:18 , Jack Lawrence <ja...@apple.com> wrote: > > Jens: Why? There are significant benefits to value semantics for this type of > problem, for the reasons laid out in the WWDC videos. It would be helpful to > know why you disagree in this case—maybe there are solutions to the issues > you’re thinking of. > > Rick: I’d think that value semantics would be the right choice here. When you > do a mutation, you would copy the state of the entire diagram. It should be > efficient via COW, but if not you can implement you own more fine-grained COW > types with isUniquelyReferenced(). This would allow you to easily support > things like undo.
The more I consider this, the more I think value semantics won't work for me. I think, to take advantage of the easy undo feature, my entire model *must* be implemented with value semantics. But my model has implicit reference semantics: multiple instances of a part can share a PartDefinition; it is intended that if the PartDefinition changes, all the referencing instances get the change. There are additional situations in which reference semantics are at play, as well: a PartDefinition can have one or more labels, but each instance can specify the relative location of the label for that instance. So, there is struct that contains a position and a reference to the label in the PartDefinition. But if the contents of the label changes, all the instances need to see that change. I don't think I get to take advantage of value semantics, and it makes me wonder if any typical, non-trivial model's object graph really has no reference semantics. > > Jack >> On Aug 1, 2016, at 4:32 PM, Jens Alfke via swift-users >> <swift-users@swift.org> wrote: >> >> >>> On Aug 1, 2016, at 1:19 AM, Rick Mann via swift-users >>> <swift-users@swift.org> wrote: >>> >>> It seems like reference semantics are more appropriate here. >> >> Yes, they are. (Just because structs exist doesn’t mean you have to use them >> everywhere.) >> >> —Jens >> _______________________________________________ >> swift-users mailing list >> swift-users@swift.org >> https://lists.swift.org/mailman/listinfo/swift-users > -- Rick Mann rm...@latencyzero.com _______________________________________________ swift-users mailing list swift-users@swift.org https://lists.swift.org/mailman/listinfo/swift-users