[swift-evolution] When to use argument labels, part DEUX

Dave Abrahams dabrahams at apple.com
Mon Feb 8 07:15:54 CST 2016


In the case of this particular API, it's OK, because normal users can
always call copy().

In general, when importing APIs whose base name would end in a
preposition and whose only parameter would have a default, we could
choose to:

1. drop the preposition.
2. drop the default
3. allow the preposition to dangle when no argument is passed
4. complicate the rules to allow the preposition to migrate inside the
   parens
5. change the rules so that the preposition is always inside the parens

I think #1, #2, #3, and #4 all correspond to guidelines that end up
deterring people from evolving APIs by adding a default for the first
argument when it's part of a prepositional phrase.

Remember the problem with #5: move(toX: x, y: y) is ugly.  On the other
hand, there not so many of these APIs, there are ways to (manually)
smooth such an API, e.g.  move(to: (x,y)) or move(to: Point(x,y)), and
that is the only way to unambiguously distribute a preposition across
arguments in a case where it doesn't apply to *all* arguments:

  move(to: (x,y), by: .Sliding)

On the other other hand, I don't find move(toX: x, y: y, by: .Sliding)
to be ambiguous in practice, just a bit ugly.

So maybe prepositions should go inside parentheses.

on Mon Feb 08 2016, Matthew Judge <swift-evolution at swift.org> wrote:

> Agree that basing the preposition location on whether there is a
> default value is unfortunate. The problem is "Zone" is not
> redundant/needless when calling it with the default value.
>
> copyWith()
>
> If I were asking "what zone?" Ok it's the default zone, but I'm just asking "with what?"
>
>> On Feb 7, 2016, at 10:48, Dave Abrahams via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> 
>> on Sat Feb 06 2016, Douglas Gregor <swift-evolution at swift.org> wrote:
>> 
>>>> On Feb 6, 2016, at 10:08 PM, Dave Abrahams via swift-evolution
>>>> <swift-evolution at swift.org> wrote:
>>>> 
>>>> 
>>>>> on Sat Feb 06 2016, Thorsten Seitz <swift-evolution at swift.org> wrote:
>>>>> 
>>>>> So the preposition should move into the argument label if the argument is optional?
>>>>> 
>>>>> copy(withZone: zone = nil)
>>>> 
>>>> That's a good idea.
>>> 
>>> It seems unfortunate that the placement of the preposition should
>>> change depending on whether there is a default argument or not,
>>> especially since it is reasonable to imagine that an API evolves to
>>> gain a default argument later on.
>> 
>> You're right; it would complicate the rules significantly, too.
>> 
>>>    - Doug
>>> 
>>>> 
>>>>> -Thorsten 
>>>>> 
>>>>>> Am 06.02.2016 um 14:45 schrieb Matthew Judge via swift-evolution
>>>>>> <swift-evolution at swift.org>:
>>>>>> 
>>>>>> Very first method
>>>>>> 
>>>>>> copyWith(zone: Zone = nil)
>>>>>> 
>>>>>> can be called as
>>>>>> 
>>>>>> copyWith()
>>>>>> 
>>>>>> I'm assuming this is still something we don't want right?
>>>>>> 
>>>>>>> On Feb 6, 2016, at 02:16, Douglas Gregor via swift-evolution
>>>>>>> <swift-evolution at swift.org> wrote:
>>>>>>> 
>>>>>>> 
>>>>>>>> On Feb 5, 2016, at 1:32 PM, Dave Abrahams via swift-evolution
>>>>>>>> <swift-evolution at swift.org> wrote:
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Given all the awesome feedback I've gotten on this thread, I went back
>>>>>>>> to the drawing board and came up with something new; I think this one
>>>>>>>> works.  The previously-stated goals still apply:
>>>>>>> 
>>>>>>>> [snip goals]
>>>>>>> 
>>>>>>>> P.S. Doug is presently working on generating new importer results, based
>>>>>>>>   on these guidelines, for your perusal.  They should be ready soon.
>>>>>>> 
>>>>>>> 
>>>>>>> Here’s a link:
>>>>>>> 
>>>>>>>    https://github.com/apple/swift-3-api-guidelines-review/pull/10/files
>>>>>>> 
>>>>>>> Feedback welcome!
>>>>>>> 
>>>>>>>    - Doug
>>>>>>> 
>>>>>>> _______________________________________________
>>>>>>> swift-evolution mailing list
>>>>>>> swift-evolution at swift.org
>>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution at swift.org
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution at swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>> 
>>>> -- 
>>>> -Dave
>>>> 
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution at swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>> 
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>> 
>> -- 
>> -Dave
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-- 
-Dave



More information about the swift-evolution mailing list