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

Dave Abrahams dabrahams at apple.com
Sat Feb 13 15:19:53 CST 2016


on Sat Feb 13 2016, Brent Royal-Gordon <brent-AT-architechies.com> 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:)

The latter two names mean the same thing to my eye.

> 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 don't think there's any advantage in trying to make all these
(different) operations look the same.

> 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.

I think that issue pales in importance when compared with expressing the
right semantics.  If you get that right, whether or not the operation is
in fact symmetric becomes academic.

-- 
-Dave


More information about the swift-evolution mailing list