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

Brent Royal-Gordon brent at architechies.com
Sat Feb 13 14:34:33 CST 2016


> 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:)

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



More information about the swift-evolution mailing list