Ed/ing, InPlace, Set/SetAlgebra naming resolution

I'm good with that.

+1

-- E

···

On Feb 11, 2016, at 12:43 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:

Just thinking out loud here:

"x's intersection with y" makes sense. So "x.intersection(with: y)" makes sense. That's already in Dave's diff.

Unfortunately the same doesn't work well for "x's union with y" — should "x.union(with: y)" be a mutating or nonmutating operation? Hard to tell.

How about we just move to ∪ and ∪= operators and call it a day? :-)

On Thu, Feb 11, 2016 at 11:36 AM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:
Assuming one would want to avoid the -ed suffix (and also -ing), one might consider:

* intersectionOf(), orOf(), unionOf() (or "With" over "Of")
* setIntersection(), setOr(), setUnion(),
* intersectionResult(), orResult(), unionResult(),
etc

-- E

On Feb 11, 2016, at 12:28 PM, Jacob Bandes-Storch <jtbandes@gmail.com <mailto:jtbandes@gmail.com>> wrote:

"intersected" sounds okay to me. "unioned" is borderline, and "ored" is not something I'd want in the standard library. Neither is "oring".

On Thu, Feb 11, 2016 at 11:25 AM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:
I see the -ed versions as short for -edSet, with the Set being implied. Under this reasoning, unioned == unionedSet, intersected == intersectedSet, thus acting as nouns not verbs, and used for non-mutating application.

inPlace is only for mutating application. I mildly prefer the shorter union to unionInPlace, although I could argue both sides. (The latter is clearer but longer, the former is the short verb action that the whole guideline thing is supposed to endorse.)

-- E

On Feb 11, 2016, at 12:19 PM, Jacob Bandes-Storch <jtbandes@gmail.com <mailto:jtbandes@gmail.com>> wrote:

On Thu, Feb 11, 2016 at 11:09 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Non-Mutating, returning new value: unioned(with), intersected(with), exclusiveOred(with)

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.

So do the -ed versions, IMO. That's why -InPlace is such a convenient suffix.

Jacob

+1 for this suggestion.

Jim

jimhillhouse@me.com
512-484-9489

···

Sent from Jim's iPhone

On Feb 11, 2016, at 1:36 PM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

Assuming one would want to avoid the -ed suffix (and also -ing), one might consider:

* intersectionOf(), orOf(), unionOf() (or "With" over "Of")
* setIntersection(), setOr(), setUnion(),
* intersectionResult(), orResult(), unionResult(),
etc

-- E

On Feb 11, 2016, at 12:28 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:

"intersected" sounds okay to me. "unioned" is borderline, and "ored" is not something I'd want in the standard library. Neither is "oring".

On Thu, Feb 11, 2016 at 11:25 AM, Erica Sadun <erica@ericasadun.com> wrote:
I see the -ed versions as short for -edSet, with the Set being implied. Under this reasoning, unioned == unionedSet, intersected == intersectedSet, thus acting as nouns not verbs, and used for non-mutating application.

inPlace is only for mutating application. I mildly prefer the shorter union to unionInPlace, although I could argue both sides. (The latter is clearer but longer, the former is the short verb action that the whole guideline thing is supposed to endorse.)

-- E

On Feb 11, 2016, at 12:19 PM, Jacob Bandes-Storch <jtbandes@gmail.com> wrote:

On Thu, Feb 11, 2016 at 11:09 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:
Non-Mutating, returning new value: unioned(with), intersected(with), exclusiveOred(with)

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.

So do the -ed versions, IMO. That's why -InPlace is such a convenient suffix.

Jacob

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Here are some thoughts after having quietly pondered the mutating method naming discussion for a while.

My view is that an "ed/ing" mutation rule is fraught with undesirable compromises. It's tempting because it works so well in the majority of cases, but it seems that cases where it doesn't work are not uncommon, even when the scope of the discussion is narrowed to a small set of operations such as this. We're trying to play nice with English, but we're butting up against its fundamental lack of clarity.

As far as I see it, these are the options (forgive me for repeating much of what others have said -- I'd like to accurately convey my perception of the situation as a whole):

1. Move forward with ed/ing-based guidelines that work well in many cases. For the cases which don't work well, we can either:

Have explicit exceptions, likely leading to overly-complicated guidelines that people may not be bothered to follow.
Leave it up to the developer to decide what's best on a case-by-case basis, likely leading to inconsistencies and lots of time spent on discussions of this magnitude.

There's also a worrying amount of uncertainty and subjectivity involved in identifying the situations where the base guidelines don't work well, particularly for developers who aren't experts in English.

2. Use "inPlace" or some other simple adornment that can be universally applied to a method without exceptions.

An inPlace suffix would be a significant eyesore for such a common pattern. There doesn't seem to be another less obtrusive suffix that properly conveys mutation, so we're either stuck with inPlace, or we could try to find a more terse symbolic pattern (the same idea as Ruby's postfix ! to indicate mutation). Nothing desirable comes to mind, though.

3. Add a language-level feature that allows a method on a type which returns a value of that same type to be called in a way that mutates the callee.

Even when naming isn't an issue, defining mutating / non-mutating versions of method is somewhat tedious and inflates the type's interface. Any method that returns a value of the callee's type is a valid candidate for a mutating version of that API, but defining the mutating version is 100% boilerplate.

Support from the compiler would eliminate this boilerplate as well as this seemingly-unsolvable naming problem at the cost of some additional complexity in the compiler.

I can see two options off the top of my head. First, a method that returns the same type as the callee mutates when its return value is unused instead of producing a warning:

let c = a.union(with: b) // Doesn't mutate.
a.union(with: b) // Mutates.

This is somewhat subtle and has some potential for confusion, but I think Swift's strong immutability features would make it extremely rare for this pattern to create bugs.

Or, we can create a special syntax for mutating a callee with the return value of its method:

a .= union(with: b) // First thing that comes to mind. It's conceptually similar to += and friends and makes assignment explicit.
a = .union(with: b) // Similar idea, looks less like you're calling a global method called union.

My personal preference lies strongly in option 3 with roughly equal preference for either sub-option, but I'd really like to hear what others think.

Jarod

···

On Feb 11, 2016, at 11:43, Jacob Bandes-Storch via swift-evolution <swift-evolution@swift.org> wrote:

Just thinking out loud here:

"x's intersection with y" makes sense. So "x.intersection(with: y)" makes sense. That's already in Dave's diff.

Unfortunately the same doesn't work well for "x's union with y" — should "x.union(with: y)" be a mutating or nonmutating operation? Hard to tell.

How about we just move to ∪ and ∪= operators and call it a day? :-)

On Thu, Feb 11, 2016 at 11:36 AM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:
Assuming one would want to avoid the -ed suffix (and also -ing), one might consider:

* intersectionOf(), orOf(), unionOf() (or "With" over "Of")
* setIntersection(), setOr(), setUnion(),
* intersectionResult(), orResult(), unionResult(),
etc

-- E

On Feb 11, 2016, at 12:28 PM, Jacob Bandes-Storch <jtbandes@gmail.com <mailto:jtbandes@gmail.com>> wrote:

"intersected" sounds okay to me. "unioned" is borderline, and "ored" is not something I'd want in the standard library. Neither is "oring".

On Thu, Feb 11, 2016 at 11:25 AM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:
I see the -ed versions as short for -edSet, with the Set being implied. Under this reasoning, unioned == unionedSet, intersected == intersectedSet, thus acting as nouns not verbs, and used for non-mutating application.

inPlace is only for mutating application. I mildly prefer the shorter union to unionInPlace, although I could argue both sides. (The latter is clearer but longer, the former is the short verb action that the whole guideline thing is supposed to endorse.)

-- E

On Feb 11, 2016, at 12:19 PM, Jacob Bandes-Storch <jtbandes@gmail.com <mailto:jtbandes@gmail.com>> wrote:

On Thu, Feb 11, 2016 at 11:09 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:
Non-Mutating, returning new value: unioned(with), intersected(with), exclusiveOred(with)

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.

So do the -ed versions, IMO. That's why -InPlace is such a convenient suffix.

Jacob

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Good idea!

-Thorsten

···

Am 11.02.2016 um 19:52 schrieb Craig Cruden <ccruden@novafore.com>:

or x.merge(x) for mutating union.

On 2016-02-12, at 1:49:23, Thorsten Seitz via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I’d like to repeat my suggestion:

mutating (verbs):
x.intersect(x)
x.add(x)
x.subtract(x)

So, someone thought. I mean, if one is going to mess-up their English,
why not 'intersectioning'? I'll just assume 'unioning' was a case of

Jim

I've come down with a bad case of Dave, myself.

jimhillhouse@me.com
512-484-9489

Sent from Jim's iPhone

The reason I commented on ‘union’ as a verb was because, with
‘unioning’ proposed in SetAlgebra, I figured someone in the Swift
group must have been a fan of older verb-form usage of ‘union’.

Yep, someone must've. ;-)

All kidding aside, brutally mangling 'union' into 'unioning' is was
obviously a poor choice. Now I'm just relieved 'intersectioning' was
avoided. ;-)

I guess what's obvious to some is not as obvious to others.

···

on Thu Feb 11 2016, Jim Hillhouse <swift-evolution@swift.org> wrote:

On Feb 11, 2016, at 7:29 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Thu Feb 11 2016, James Hillhouse IV <swift-evolution@swift.org> wrote:

That’s what I get for basing my comment on ‘Wiki’-anything.

On Feb 11, 2016, at 5:05 PM, Dave Abrahams via swift-evolution >>>> <swift-evolution@swift.org> wrote:

on Thu Feb 11 2016, Jim Hillhouse >>>> <swift-evolution@swift.org >>>> <mailto:swift-evolution@swift.org>> >>>> wrote:

Are these function names being based on the present participle of each verb, e.g. 'union' and 'intersect'?

The present participle of 'union' is technically speaking,
'unioning'.

Technically speaking, I'm pretty sure you can't have a participle of
anything that isn't a verb, and “union” isn't one AFAICT.

single word requests - Verb for "to form the union of A and B" - English Language & Usage Stack Exchange
<single word requests - Verb for "to form the union of A and B" - English Language & Usage Stack Exchange;

But it is not widely used. In fact, in both Pages and Word, 'unioning'
is flagged as a misspelling of 'union'.

The present participle of 'intersect' is 'intersecting';
'intersection' is a noun.

As currently presented, the use of 'union' and 'intersection' are a
mixing of rarely used though correct present participle verb tense and
a noun. I think it would be better to recognize that 'union' and
'intersection' are two universally used mathematical terms and to
forego the suggested verb tense gymnastics.

Jim

jimhillhouse@me.com
512-484-9489

Sent from Jim's iPhone

On Feb 11, 2016, at 12:09 PM, Xiaodi Wu via swift-evolution >>>>>> <swift-evolution@swift.org> wrote:

MHO: +1 on the intention of using less unwieldy names, but -1 on the
specific solution. I fear that the current solution has some
inexplicable inconsistencies and some Englishing which verges, again
MHO, on Hungarianisms that others have mentioned are to be
explicitly avoided.

For example, why is it intersection() but unioning()? Surely it
should be either intersecting() and unioning() or intersection() and
union()? Also, I understand that there's precedent elsewhere and
that uniting() is not a good counterpart to union(), but unioning()
is a pretty unsavory mangling of the noun. And then we have
exclusiveOring(), which is just not English.

On Thu, Feb 11, 2016 at 11:38 AM Dave Abrahams via swift-evolution >>>>>>> <swift-evolution@swift.org> wrote:

Hi All,

The API guidelines working group took up the issue of the InPlace suffix
yesterday, and decided that it was not to be used anywhere in the
standard library. We are planning to apply the changes shown here
<https://gist.github.com/dabrahams/d872556291a3cb797bd5&gt; to the API of
SetAlgebra (and consequently Set) to make it conform to the guidelines
under development.

Comments welcome as usual,

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
<mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
<mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Dave

x.sort(inPlace: true) can't work with those definitions.

···

On Feb 11, 2016, at 10:33 PM, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

On Feb 11, 2016, at 10:30 PM, Chris Lattner <clattner@apple.com> wrote:

On Feb 11, 2016, at 10:28 PM, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

I don’t know if this has been suggested already… but why not just use the same name and have an `inPlace` parameter with a default value?

inplace, or not, fundamentally affects the operation, including the return type. On a struct, it is the different between the method being mutating or not.

-Chris

The return type is not always different, but in the case where it is and when we need mutating, can’t overloads solve this problem?

mutating func sort() {}
func sort(inPlace: Bool) -> T {}

Maybe I’m just overlooking something really obvious here…

--
Greg Parker gparker@apple.com Runtime Wrangler

Yes… yes I am…

···

On Feb 11, 2016, at 10:33 PM, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

On Feb 11, 2016, at 10:30 PM, Chris Lattner <clattner@apple.com> wrote:

On Feb 11, 2016, at 10:28 PM, David Owens II via swift-evolution <swift-evolution@swift.org> wrote:

I don’t know if this has been suggested already… but why not just use the same name and have an `inPlace` parameter with a default value?

inplace, or not, fundamentally affects the operation, including the return type. On a struct, it is the different between the method being mutating or not.

-Chris

The return type is not always different, but in the case where it is and when we need mutating, can’t overloads solve this problem?

mutating func sort() {}
func sort(inPlace: Bool) -> T {}

Maybe I’m just overlooking something really obvious here…

-David
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I was thinking of maybe:

x.remove(x) for subtract (java mutable remove).

···

On 2016-02-12, at 2:00:41, Thorsten Seitz <tseitz42@icloud.com> wrote:

Good idea!

-Thorsten

Am 11.02.2016 um 19:52 schrieb Craig Cruden <ccruden@novafore.com <mailto:ccruden@novafore.com>>:

or x.merge(x) for mutating union.

On 2016-02-12, at 1:49:23, Thorsten Seitz via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

I’d like to repeat my suggestion:

mutating (verbs):
x.intersect(x)
x.add(x)
x.subtract(x)

Not to mention - mutating (in my limited and aged math knowledge) is
NOT mathematical (computer simulations might use math in simulations
which simulating something that mutates)

Mathematicians (typically) don’t mutate - they might be mutants…. but
they don’t mutate their equations.

When was the last time you saw a mutating equation? If equations
mutate then it makes it much more difficult to prove correctness.

Probably why even OO programming languages don’t allow you to mutate
an Integer or Decimal ….. bad things can happen.

Union and intersection have more in common with operations like + and
- which also do not mutate the values.

Let's not go too far with this. Euclid invented the GCD algorithm,
which was originally expressed iteratively and therefore can be seen to
be mutating variables. The whole concept of “algorithm” was named after
an arabic mathematician.

···

on Fri Feb 12 2016, Craig Cruden <swift-evolution@swift.org> wrote:

:p

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.
* I think you have the nature of the words mis-assigned. In my
opinion in this rare case, union, intersection, and exclusiveOr act
as verbs as they are mathematical set operations. For example,
"what is the result of A union B?" is a reasonable thing to say to
a math person or put on an exam question, etc.

On 2016-02-12, at 22:20:01, Thorsten Seitz via swift-evolution >> <swift-evolution@swift.org> wrote:

I beg to disagree with your reasoning.
I think "union" is more commonly used as a noun and "intersection"
certainly is not a verb. Your example sounded weird for me (but
maybe that's because I'm not a native speaker) and I would rather
expect the question to be "What is the union of A and B?"

-Thorsten

Am 11.02.2016 um 20:09 schrieb Erica Sadun via swift-evolution >> <swift-evolution@swift.org
<mailto:swift-evolution@swift.org>>:

My expectations is that the standard operators act upon a set, changing the set.

set1.union(with: set2) tells set1 to perform the union.
set1.unioned(with: set2) creates a new instance where set1 has been unioned with set 2.

Naming: intersected, unioned, and exclusiveOred over intersecting,
unioning, exclusiveOring.
Mutating: union, intersection, exclusiveOr.
Non-Mutating, returning new value: unioned(with), intersected(with), exclusiveOred(with)

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.
* I think you have the nature of the words mis-assigned. In my
opinion in this rare case, union, intersection, and exclusiveOr act
as verbs as they are mathematical set operations. For example,
"what is the result of A union B?" is a reasonable thing to say to
a math person or put on an exam question, etc.

Importantly, they produce significant side effects, and should be
treated as verbs that operate upon the receiver, updating the
receiver, establishing their use for mutating ops.

Dave wrote:

- use nouns for methods with no side effects (or only incidental ones, like logging)
- use verbs for methods with significant side-effects

-- E

On Feb 11, 2016, at 9:52 AM, Dave Abrahams via swift-evolution >>>> <swift-evolution@swift.org >>>> <mailto:swift-evolution@swift.org>> >>>> wrote:

Hi All,

The API guidelines working group took up the issue of the InPlace suffix
yesterday, and decided that it was not to be used anywhere in the
standard library. We are planning to apply the changes shown here
<SetAlgebra (and Set) naming resolution · GitHub
<https://gist.github.com/dabrahams/d872556291a3cb797bd5&gt;&gt; to the
API of
SetAlgebra (and consequently Set) to make it conform to the guidelines
under development.

Comments welcome as usual,

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
<mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
<mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Dave

I also am greatly in favor of set algebra using infix and assignment operators. As already mentioned, this removes ambiguity about mutating or not mutating.

In addition, I believe this is not an abuse of operators such that they become confusing: all of the operators are familiar from other uses. Furthermore, I feel this adds consistency mathematically with the rest of the language: all of the major algebras (integers, reals, booleans) and now sets would have similar syntax and "feel".

Then again, I might have an excessive preference for mathematical constructs in Swift to come out "cute", which isn't necessarily the goal of Swift.

Just my 2 cents,

Donald Pinckney

···

On Feb 12, 2016, at 2:33 PM, Craig Cruden via swift-evolution <swift-evolution@swift.org> wrote:

I like the set operators being “operator” infix symbols - and would be happy with those.

Definitely far better than some of the programmer assaults on the english language so far :p

On 2016-02-13, at 5:30:20, Sébastien Blondiau via swift-evolution <swift-evolution@swift.org> wrote:

Using only the operators | & - ^ |= &= -= ^= for the operations on Set would simplify the code and resolve the problem of the names of these functions. Set do not really need these functions as method, only the operators would be enough, like the BitwiseOperationsType which do not have the methods xor and orInPlace ...

With the operators, the question of "does this function mutate?" would not be anymore. The code would get clarity and brevity without problem of naming. Isn’t that the API Design Guidelines?

--
Sébastien

Le 12 févr. 2016 à 00:24, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> a écrit :

The API guidelines working group took up the issue of the InPlace suffix
yesterday, and decided that it was not to be used anywhere in the
standard library. We are planning to apply the changes shown here
<https://gist.github.com/dabrahams/d872556291a3cb797bd5&gt; to the API of
SetAlgebra (and consequently Set) to make it conform to the guidelines
under development.

My suggestions:

  union -> union
  intersect -> intersection
  subtract -> subtraction

  unionInPlace -> unite
  intersectInPlace -> intersect
  subtractInPlace -> subtract

In other words, treat the mutating forms as imperative verbs and the nonmutating forms as nouns. This basically makes the nonmutating forms into accessors, which I think is a good alternative given the trouble we're having with -ing/-ed.

That still leaves exclusiveOr, which is frankly a horrible name to begin with. I think we have to derive a name from the "symmetric difference" terminology, giving us

  exclusiveOr -> difference
  exclusiveOrInPlace -> differ

However, given the difficulty we're having coming up with names, we might want to explore using operators instead.

  union -> |
  intersect -> &
  subtract -> -
  exclusiveOr -> ^

This gives us extremely straightforward mutating operators, of course, since we do have a convention for in-place operators:

  unionInPlace -> |=
  intersectInPlace -> &=
  subtract -> -=
  exclusiveOr -> ^=

Some things to like about these operators:

* They are not used for anything on sequences or collections, so they don't overload existing concepts like concatenation with incompatible semantics.
* They have the same commutativity and transitivity as the associated integer operations.
* The bitwise forms of `|` and `&` are already documented (in `_DisallowMixedSignArithmetic`) as the union and intersection of the bits, and `^` is documented in a compatible way. Meanwhile, `-` literally means "subtraction", the exact same operation we're exposing.
* And of course, it's just *nice* to not have to write long, unwieldy method names for fundamental operations.

Swift generally tries not to overload operators too much, but I think in this case, these overloads would be appropriate and helpful, while also getting us out of a sticky naming problem.

--
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

An algorithm (as far as I know) is not inherently mutable. It is a process of apply a certain process (or a certain function) over and over again until you have a result.

If you processed it in writing (the common form of computing at the time) - you would write line after line of the results until you could break it down no farther (GCD).

Each step clearly documented, clearly written down (not erasing a value and inserting a new value).

Basically you are applying a function on smaller and smaller bits (recursion) and recursion is not a mutable concept.

But I think that is more than enough digression :p

···

On 2016-02-13, at 5:21:46, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Fri Feb 12 2016, Craig Cruden <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Not to mention - mutating (in my limited and aged math knowledge) is
NOT mathematical (computer simulations might use math in simulations
which simulating something that mutates)

Mathematicians (typically) don’t mutate - they might be mutants…. but
they don’t mutate their equations.

When was the last time you saw a mutating equation? If equations
mutate then it makes it much more difficult to prove correctness.

Probably why even OO programming languages don’t allow you to mutate
an Integer or Decimal ….. bad things can happen.

Union and intersection have more in common with operations like + and
- which also do not mutate the values.

Let's not go too far with this. Euclid invented the GCD algorithm,
which was originally expressed iteratively and therefore can be seen to
be mutating variables. The whole concept of “algorithm” was named after
an arabic mathematician.

:p

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.
* I think you have the nature of the words mis-assigned. In my
opinion in this rare case, union, intersection, and exclusiveOr act
as verbs as they are mathematical set operations. For example,
"what is the result of A union B?" is a reasonable thing to say to
a math person or put on an exam question, etc.

On 2016-02-12, at 22:20:01, Thorsten Seitz via swift-evolution >>> <swift-evolution@swift.org> wrote:

I beg to disagree with your reasoning.
I think "union" is more commonly used as a noun and "intersection"
certainly is not a verb. Your example sounded weird for me (but
maybe that's because I'm not a native speaker) and I would rather
expect the question to be "What is the union of A and B?"

-Thorsten

Am 11.02.2016 um 20:09 schrieb Erica Sadun via swift-evolution >>> <swift-evolution@swift.org
<mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>>:

My expectations is that the standard operators act upon a set, changing the set.

set1.union(with: set2) tells set1 to perform the union.
set1.unioned(with: set2) creates a new instance where set1 has been unioned with set 2.

Naming: intersected, unioned, and exclusiveOred over intersecting,
unioning, exclusiveOring.
Mutating: union, intersection, exclusiveOr.
Non-Mutating, returning new value: unioned(with), intersected(with), exclusiveOred(with)

Reasoning:

* I think the -ing endings sound unnatural, stilted, and unmathematical. They make me wince.
* I think you have the nature of the words mis-assigned. In my
opinion in this rare case, union, intersection, and exclusiveOr act
as verbs as they are mathematical set operations. For example,
"what is the result of A union B?" is a reasonable thing to say to
a math person or put on an exam question, etc.

Importantly, they produce significant side effects, and should be
treated as verbs that operate upon the receiver, updating the
receiver, establishing their use for mutating ops.

Dave wrote:

- use nouns for methods with no side effects (or only incidental ones, like logging)
- use verbs for methods with significant side-effects

-- E

On Feb 11, 2016, at 9:52 AM, Dave Abrahams via swift-evolution >>>>> <swift-evolution@swift.org <mailto:swift-evolution@swift.org> >>>>> <mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>> >>>>> wrote:

Hi All,

The API guidelines working group took up the issue of the InPlace suffix
yesterday, and decided that it was not to be used anywhere in the
standard library. We are planning to apply the changes shown here
<SetAlgebra (and Set) naming resolution · GitHub
<https://gist.github.com/dabrahams/d872556291a3cb797bd5&gt;&gt; to the
API of
SetAlgebra (and consequently Set) to make it conform to the guidelines
under development.

Comments welcome as usual,

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
<mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
<mailto:swift-evolution@swift.org <mailto:swift-evolution@swift.org>>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

Dang it, more mistakes. Trying again:

   func invertingMembershipOfContentsOf(other: Self) -> Self
   mutating func invertMembershipOfContentsOf(other: Self)

···

on Sat Feb 13 2016, Dave Abrahams <swift-evolution@swift.org> wrote:

on Sat Feb 13 2016, Dave Abrahams <dabrahams-AT-apple.com> wrote:

The following message is a courtesy copy of an article
that has been posted to gmane.comp.lang.swift.evolution as well.

on Fri Feb 12 2016, Ricardo Parada <swift-evolution@swift.org> wrote:

Hi all,

I can’t make up my mind. Let me propose two different alternatives
that I’m not sure if they have been considered:

ALTERNATIVE 1

Non-mutable (noun-based)

- func union(other: Self) -> Self
+ func union(other: Self) -> Self Assumes union is a noun, i.e. not a verb

- func intersect(other: Self) -> Self
+ func intersection(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func subtraction(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func symmetricSubtraction(other: Self) -> Self

Mutable (verb-based)

- mutating func unionInPlace(other: Self)
+ mutating func unite(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func subtract(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func symmetricSubtract(other: Self)

Comments:

With this alternative we keep the union name which I assume is
popular. However, one has to accept unite as a verb (for the mutable
version) as I wanted all the mutable methods use verbs for
consistency. I think unite is acceptable because it can be found in
the dictionary and it is a verb.

Notice that all the non-mutable methods use nouns: union,
intersection, subtraction and symmetricSubtraction.

I understand some may oppose to symmetricSubtraction saying that
symmetricSubraction is not as common as "exclusive or". However,
using symmetricSubtraction is consistent with subtraction and it hints
to a variation of the “subtraction" operation. We will get used to it
quickly / easily.

The mutable methods all use verbs: unite, intersect, subtract and symmetricSubtract.

ALTERNATIVE 2

Non-mutable

- func union(other: Self) -> Self
+ func adding(other: Self) -> Self

- func intersect(other: Self) -> Self
+ func intersecting(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func exclusiveOring(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func removing(other: Self) -> Self

Mutable

- mutating func unionInPlace(other: Self)
+ mutating func add(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func exclusiveOr(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func remove(other: Self)

Comments: This alternative gives up on union in favor or add. Many
may not like this, that is why I have it as the second alternative.
It brings back exclusiveOr and treats it as a verb. Some may argue
that exclusiveOr is a noun for the "exclusive or" operation.

If we are going to force Set fit the naming guidelines, I would prefer
to stay away from the mathematical terms altogether.

Sorry, a few more notes about this:

   func insertingContentsOf(other: Self) -> Self // union
   mutating func insertContentsOf(other)

"merge" might be a better verb than "insert"

   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)

Oops, left a stray "ing" in there:

    mutating func removeMembersAndAddNonMembers(in other: Self)

Another avenue for this one is:

    mutating func invertingMembershipOfContentsOf(other: Self)
    mutating func invertMembershipOfContentsOf(other: Self)

--
-Dave

Is there a reason why the same data structures are supporting both mutable and non-mutable operations?

Because Set is a Swift value type and you can control its mutability by assigning it to a constant or variable, just like an Array.

···

--
Brent Royal-Gordon
Architechies

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.

···

on Sat Feb 13 2016, Brent Royal-Gordon <brent-AT-architechies.com> wrote:

--
-Dave

Using only the operators | & - ^ |= &= -= ^= for the operations on Set
would simplify the code and resolve the problem of the names of these
functions. Set do not really need these functions as method, only the
operators would be enough, like the BitwiseOperationsType which do not
have the methods xor and orInPlace ...

We have a semantic muddle in this area, because:

* We believe that bitwise operations on integers are distinct from set
operations and should use different notation.

I'm not sure I see a significant difference. (Or at least I can easily reason about bitwise operations as working on subsets of the set: 2^31, 2^30, ..., 1)

···

On Feb 13, 2016, at 12:43, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Fri Feb 12 2016, Sébastien Blondiau <swift-evolution@swift.org> wrote:

* We believe that option sets are set-like and should use set notation.

* Yet option sets are, semantically, exactly like the bitwise aspect of
integers (i.e. the set elements are the same type as the sets themselves
and may subsume one-another).

We can't really keep all these contradictions in the air at once and not
end up with a naming mess.

With the operators, the question of "does this function mutate?" would
not be anymore. The code would get clarity and brevity without problem
of naming. Isn’t that the API Design Guidelines?

--
Sébastien

Le 12 févr. 2016 à 00:24, Brent Royal-Gordon via swift-evolution <swift-evolution@swift.org> a écrit :

The API guidelines working group took up the issue of the InPlace suffix
yesterday, and decided that it was not to be used anywhere in the
standard library. We are planning to apply the changes shown here
<https://gist.github.com/dabrahams/d872556291a3cb797bd5&gt; to the API of
SetAlgebra (and consequently Set) to make it conform to the guidelines
under development.

My suggestions:

   union -> union
   intersect -> intersection
   subtract -> subtraction

   unionInPlace -> unite
   intersectInPlace -> intersect
   subtractInPlace -> subtract

In other words, treat the mutating forms as imperative verbs and the nonmutating forms as nouns. This basically makes the nonmutating forms into accessors, which I think is a good alternative given the trouble we're having with -ing/-ed.

That still leaves exclusiveOr, which is frankly a horrible name to begin with. I think we have to derive a name from the "symmetric difference" terminology, giving us

   exclusiveOr -> difference
   exclusiveOrInPlace -> differ

However, given the difficulty we're having coming up with names, we might want to explore using operators instead.

   union -> |
   intersect -> &
   subtract -> -
   exclusiveOr -> ^

This gives us extremely straightforward mutating operators, of course, since we do have a convention for in-place operators:

   unionInPlace -> |=
   intersectInPlace -> &=
   subtract -> -=
   exclusiveOr -> ^=

Some things to like about these operators:

* They are not used for anything on sequences or collections, so they don't overload existing concepts like concatenation with incompatible semantics.
* They have the same commutativity and transitivity as the associated integer operations.
* The bitwise forms of `|` and `&` are already documented (in `_DisallowMixedSignArithmetic`) as the union and intersection of the bits, and `^` is documented in a compatible way. Meanwhile, `-` literally means "subtraction", the exact same operation we're exposing.
* And of course, it's just *nice* to not have to write long, unwieldy method names for fundamental operations.

Swift generally tries not to overload operators too much, but I think in this case, these overloads would be appropriate and helpful, while also getting us out of a sticky naming problem.

--
Brent Royal-Gordon
Architechies

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

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

···

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

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@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I would, personally, be very careful about discarding the mathematical terms since they are so widely used and understood.

One issue is that it’s going to be hard to search for the operation I want considering I won’t be looking for "func invertingMembershipOfContentsOf(other: Self) -> Self”. I’m concerned people are going to have to do mental gymnastics to build the map from math term to Swift function every time they want to look for a set operation method. “func invertingMembershipOfContentsOf(other: Self) -> Self” doesn’t exactly seem to fit in the commonly held Venn diagram mental model of set operations. You could always have a documentation comment that specifies the mathematical term so that people didn’t have to double check themselves every time.

That being said, if the autocomplete issue is not a concern, I’m of the opinion that the names Ricardo proposed are short, clear, and are not so hard to fit to my Venn diagram mental model.

However, I tend to think that if there has to be this much dancing to name a set of fundamental operations, the guidelines aren’t accomplishing their goal. It’s going to make it that much harder for people do design their own APIs. I'm having quite a time trying to conform Mattt’s Surge API to the guidelines.

Tyler

···

On Feb 13, 2016, at 9:09 PM, Ricardo Parada via swift-evolution <swift-evolution@swift.org> wrote:

Hi Dave,

I would be okay with staying away from the mathematical terms similar to what you are suggesting except that the union can still be made more concise if you use merged / merge for the base name and shorten the labels to a bare minimum without loosing clarity. In addition, the merge can have a second parameter with a default to false in order to implement the symmetric difference (a.k.a. exclusive or). Recall that symmetric difference is the union of two sets and then removing the intersection (or members in common). I think it looks perfect (concise and clear). What does everybody else think?

Non-mutable

let union = a.merged(with: b)
let intersection = a.members(in: b)
let difference = a.removingMembers(in: b)
let symmetricDifference = a.merged(with: b, removingMembersInCommon: true)

Mutable (In-Place)

a.merge(with: b) // union in-place
a.removeMembers(notIn: b) // intersect in-place
a.removeMembers(in: b) // difference in-place
a.merge(with: b, removeMembersInCommon: true) // symmetric difference in-place

Ricardo Parada

On Feb 13, 2016, at 1:16 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

on Fri Feb 12 2016, Ricardo Parada <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi all,

I can’t make up my mind. Let me propose two different alternatives
that I’m not sure if they have been considered:

ALTERNATIVE 1

Non-mutable (noun-based)

- func union(other: Self) -> Self
+ func union(other: Self) -> Self Assumes union is a noun, i.e. not a verb

- func intersect(other: Self) -> Self
+ func intersection(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func subtraction(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func symmetricSubtraction(other: Self) -> Self

Mutable (verb-based)

- mutating func unionInPlace(other: Self)
+ mutating func unite(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func subtract(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func symmetricSubtract(other: Self)

Comments:

With this alternative we keep the union name which I assume is
popular. However, one has to accept unite as a verb (for the mutable
version) as I wanted all the mutable methods use verbs for
consistency. I think unite is acceptable because it can be found in
the dictionary and it is a verb.

Notice that all the non-mutable methods use nouns: union,
intersection, subtraction and symmetricSubtraction.

I understand some may oppose to symmetricSubtraction saying that
symmetricSubraction is not as common as "exclusive or". However,
using symmetricSubtraction is consistent with subtraction and it hints
to a variation of the “subtraction" operation. We will get used to it
quickly / easily.

The mutable methods all use verbs: unite, intersect, subtract and symmetricSubtract.

ALTERNATIVE 2

Non-mutable

- func union(other: Self) -> Self
+ func adding(other: Self) -> Self

- func intersect(other: Self) -> Self
+ func intersecting(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func exclusiveOring(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func removing(other: Self) -> Self

Mutable

- mutating func unionInPlace(other: Self)
+ mutating func add(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func exclusiveOr(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func remove(other: Self)

Comments: This alternative gives up on union in favor or add. Many
may not like this, that is why I have it as the second alternative.
It brings back exclusiveOr and treats it as a verb. Some may argue
that exclusiveOr is a noun for the "exclusive or" operation.

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 it would help with clarity, we could replace "in" with "foundIn"
above.

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

OK, I understand but it seems a little messy - basically overloading with two copies of every function on the “same” data structure.

With many collections it would lead to the underlying data structures within the collections would either end up being optimized for mutable or immutable.
In many cases the way you store the data internal to the collection would be more efficient if focused on one or the other — but not both.
I just view a mutable collection of the same “type” as fundamentally different than the immutable version of it.
There are probably of course tradeoffs - either way.

I would thought that if you want it “invisible” to the user which data structure you are selecting you would have a mutable implementation of `Set`, and an immutable
version of `Set` and if you used let it would be one implementation, and if var the other implementation — and not the enabling or disabling of certain functions on
the data type.

···

On 2016-02-14, at 3:11:54, Brent Royal-Gordon <brent@architechies.com> wrote:

Is there a reason why the same data structures are supporting both mutable and non-mutable operations?

Because Set is a Swift value type and you can control its mutability by assigning it to a constant or variable, just like an Array.

--
Brent Royal-Gordon
Architechies

Hi Dave,

I would be okay with staying away from the mathematical terms similar
to what you are suggesting except that the union can still be made
more concise if you use merged / merge for the base name and shorten
the labels to a bare minimum without loosing clarity. In addition,
the merge can have a second parameter with a default to false in order
to implement the symmetric difference (a.k.a. exclusive or). Recall
that symmetric difference is the union of two sets and then removing
the intersection (or members in common). I think it looks perfect
(concise and clear). What does everybody else think?

Non-mutable

let union = a.merged(with: b)
let intersection = a.members(in: b)
let difference = a.removingMembers(in: b)
let symmetricDifference = a.merged(with: b, removingMembersInCommon: true)

Mutable (In-Place)

a.merge(with: b) // union in-place
a.removeMembers(notIn: b) // intersect in-place
a.removeMembers(in: b) // difference in-place
a.merge(with: b, removeMembersInCommon: true) // symmetric difference in-place

I love your changes to my suggestion, Ricardo! The minor alterations I
would make are:

1. In both cases the Bool parameter ought to be called
   “removingMembersInCommon”

2. I would remove “with” from the in-place merge operation. We're
   really asking the receiver to merge b into itself. “With” gives it
   the sense that it might almost be mutating b.

···

on Sat Feb 13 2016, Ricardo Parada <rparada-AT-mac.com> wrote:

Ricardo Parada

On Feb 13, 2016, at 1:16 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org> wrote:

on Fri Feb 12 2016, Ricardo Parada <swift-evolution@swift.org >> <mailto:swift-evolution@swift.org>> wrote:

Hi all,

I can’t make up my mind. Let me propose two different alternatives
that I’m not sure if they have been considered:

ALTERNATIVE 1

Non-mutable (noun-based)

- func union(other: Self) -> Self
+ func union(other: Self) -> Self Assumes union is a noun, i.e. not a verb

- func intersect(other: Self) -> Self
+ func intersection(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func subtraction(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func symmetricSubtraction(other: Self) -> Self

Mutable (verb-based)

- mutating func unionInPlace(other: Self)
+ mutating func unite(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func subtract(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func symmetricSubtract(other: Self)

Comments:

With this alternative we keep the union name which I assume is
popular. However, one has to accept unite as a verb (for the mutable
version) as I wanted all the mutable methods use verbs for
consistency. I think unite is acceptable because it can be found in
the dictionary and it is a verb.

Notice that all the non-mutable methods use nouns: union,
intersection, subtraction and symmetricSubtraction.

I understand some may oppose to symmetricSubtraction saying that
symmetricSubraction is not as common as "exclusive or". However,
using symmetricSubtraction is consistent with subtraction and it hints
to a variation of the “subtraction" operation. We will get used to it
quickly / easily.

The mutable methods all use verbs: unite, intersect, subtract and symmetricSubtract.

ALTERNATIVE 2

Non-mutable

- func union(other: Self) -> Self
+ func adding(other: Self) -> Self

- func intersect(other: Self) -> Self
+ func intersecting(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func exclusiveOring(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func removing(other: Self) -> Self

Mutable

- mutating func unionInPlace(other: Self)
+ mutating func add(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func exclusiveOr(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func remove(other: Self)

Comments: This alternative gives up on union in favor or add. Many
may not like this, that is why I have it as the second alternative.
It brings back exclusiveOr and treats it as a verb. Some may argue
that exclusiveOr is a noun for the "exclusive or" operation.

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 it would help with clarity, we could replace "in" with "foundIn"
above.

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution
<https://lists.swift.org/mailman/listinfo/swift-evolution&gt;

--
-Dave

I could see myself supporting this naming strategy. It is semantically transparent while following the guidelines (even though I am still very sceptical about the practicability of the “be grammatical rule”). Functions like union, intersect etc. can be implemented as global generics that operate on suitable protocols.

Best,

Taras

···

On 14 Feb 2016, at 06:09, Ricardo Parada via swift-evolution <swift-evolution@swift.org> wrote:

Hi Dave,

I would be okay with staying away from the mathematical terms similar to what you are suggesting except that the union can still be made more concise if you use merged / merge for the base name and shorten the labels to a bare minimum without loosing clarity. In addition, the merge can have a second parameter with a default to false in order to implement the symmetric difference (a.k.a. exclusive or). Recall that symmetric difference is the union of two sets and then removing the intersection (or members in common). I think it looks perfect (concise and clear). What does everybody else think?

Non-mutable

let union = a.merged(with: b)
let intersection = a.members(in: b)
let difference = a.removingMembers(in: b)
let symmetricDifference = a.merged(with: b, removingMembersInCommon: true)

Mutable (In-Place)

a.merge(with: b) // union in-place
a.removeMembers(notIn: b) // intersect in-place
a.removeMembers(in: b) // difference in-place
a.merge(with: b, removeMembersInCommon: true) // symmetric difference in-place

Ricardo Parada

On Feb 13, 2016, at 1:16 PM, Dave Abrahams via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

on Fri Feb 12 2016, Ricardo Parada <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

Hi all,

I can’t make up my mind. Let me propose two different alternatives
that I’m not sure if they have been considered:

ALTERNATIVE 1

Non-mutable (noun-based)

- func union(other: Self) -> Self
+ func union(other: Self) -> Self Assumes union is a noun, i.e. not a verb

- func intersect(other: Self) -> Self
+ func intersection(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func subtraction(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func symmetricSubtraction(other: Self) -> Self

Mutable (verb-based)

- mutating func unionInPlace(other: Self)
+ mutating func unite(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func subtract(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func symmetricSubtract(other: Self)

Comments:

With this alternative we keep the union name which I assume is
popular. However, one has to accept unite as a verb (for the mutable
version) as I wanted all the mutable methods use verbs for
consistency. I think unite is acceptable because it can be found in
the dictionary and it is a verb.

Notice that all the non-mutable methods use nouns: union,
intersection, subtraction and symmetricSubtraction.

I understand some may oppose to symmetricSubtraction saying that
symmetricSubraction is not as common as "exclusive or". However,
using symmetricSubtraction is consistent with subtraction and it hints
to a variation of the “subtraction" operation. We will get used to it
quickly / easily.

The mutable methods all use verbs: unite, intersect, subtract and symmetricSubtract.

ALTERNATIVE 2

Non-mutable

- func union(other: Self) -> Self
+ func adding(other: Self) -> Self

- func intersect(other: Self) -> Self
+ func intersecting(other: Self) -> Self

- func exclusiveOr(other: Self) -> Self
+ func exclusiveOring(other: Self) -> Self

- func subtract(other: Self) -> Self
+ func removing(other: Self) -> Self

Mutable

- mutating func unionInPlace(other: Self)
+ mutating func add(other: Self)

- mutating func intersectInPlace(other: Self)
+ mutating func intersect(other: Self)

- mutating func exclusiveOrInPlace(other: Self)
+ mutating func exclusiveOr(other: Self)

- mutating func subtractInPlace(other: Self)
+ mutating func remove(other: Self)

Comments: This alternative gives up on union in favor or add. Many
may not like this, that is why I have it as the second alternative.
It brings back exclusiveOr and treats it as a verb. Some may argue
that exclusiveOr is a noun for the "exclusive or" operation.

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 it would help with clarity, we could replace "in" with "foundIn"
above.

--
-Dave

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org <mailto:swift-evolution@swift.org>
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution