[swift-evolution] ed/ing, InPlace, Set/SetAlgebra naming resolution

Matthew Judge matthew.judge at gmail.com
Sat Feb 13 14:56:21 CST 2016



On Feb 13, 2016, at 15:34, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:

>> If we are going to force Set fit the naming guidelines, I would prefer
>> to stay away from the mathematical terms altogether.
>> 
>>  func insertingContentsOf(other: Self) -> Self                 // union
>>  mutating func insertContentsOf(other)
>> 
>>  func members(in other: Self) -> Self                           // intersection
>>  mutating func removeMembers(notIn: other)
>> 
>>  func removingMembersAndAddingNonMembers(in other: Self) -> Self // symmetric difference
>>  mutating func removeMembersAndAddingNonMembers(in other: Self)
>> 
>>  func removingMembers(in other: Self) -> Self                    // subtract
>>  mutating func removeMembers(in other: Self)
> 
> If we're abandoning conventional names, I notice that intersect, subtract, and xor can be expressed fairly clearly as:
> 
>    intersect    keep{ing}MembersInCommon(with:)
>    xor        keep{ing}MembersNotInCommon(with:)
>    subtract    keep{ing}Members(notIn:)
> 

Not sure your xor replacement works as written... It doesn't imply that you need to keep all the members of the argument that aren't common as well... 

> But union is harder. It could be constructed parallel to subtract, but it might sound like intersect this way.
> 
>    union    keep{ing}Members(in:)
> 
> On the other hand, you could style union and subtract as insert and remove operations, and use keep operations for intersect and xor.
> 
> I notice, though, that one big problem with using methods is that these operations (well, except subtract) are symmetric. Having one set be the target and another be the parameter implies that the parameter is subordinate, but in reality the two are peers. That creates false impressions which are hard to overcome through naming.
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list