[swift-evolution] When to use argument labels (a new approach)

Jordan Rose jordan_rose at apple.com
Wed Feb 3 17:56:03 CST 2016


That's a matter of opinion. I personally don't like subscripts that might take O(N) time, but Cocoa certainly has them <https://developer.apple.com/library/ios/documentation/SpriteKit/Reference/SKNode_Ref/index.html#//apple_ref/doc/uid/TP40013023-CH1-SW74>.

(I was going to say I don't like subscripts that can themselves return a collection, but then I remembered slicing, which seems perfectly natural to me. So that one's withdrawn.)

Jordan

> On Feb 3, 2016, at 15:42, Jessy Catterwaul via swift-evolution <swift-evolution at swift.org> wrote:
> 
> The last example is more appropriate as a named subscript.
> 
> tracks[mediaType: .WaxCylinder, pianist: "Brahms"]
> 
> 
>> On Feb 3, 2016, at 5:34 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>> on Wed Feb 03 2016, Matt Whiteside <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> I have one comment (below) about this part:
>>> 
>>>> On Feb 2, 2016, at 18:59, Paul Cantrell via swift-evolution
>>>> <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> 
>>>> I have reservations about this. It doesn’t generalize perfectly well:
>>>> 
>>>> 	a.tracksHavingMediaType("Wax Cylinder”, andPianist: “Brahms”)
>>>> 
>>>> …strikes me as awkward compared to one of these:
>>>> 
>>>> 	a.tracksHaving(mediaType: "Wax Cylinder”, pianist: “Brahms”)
>>>> 	// or 
>>>> 	a.tracksMatchingCriteria(mediaType: "Wax Cylinder”, pianist: “Brahms”)
>>>> 	// or even
>>>> 	a.tracks(mediaType: "Wax Cylinder”, pianist: “Brahms”)
>>>> 
>>>> …especially since, in a method of that form, _all_ the arguments are
>>>> likely to have a default value of nil:
>>>> 
>>>> 	a.tracks(mediaType: "Wax Cylinder”)
>>>> 	a.tracks(pianist: “Brahms”)
>>> 
>>> I prefer the original:
>>> 
>>> a.tracksHavingMediaType("Wax Cylinder", andPianist: "Brahms”)
>>> 
>>> to any of these,
>>> 
>>> a.tracksHaving(mediaType: "Wax Cylinder", pianist: "Brahms")
>>> // or
>>> a.tracksMatchingCriteria(mediaType: "Wax Cylinder", pianist: "Brahms")
>>> // or even
>>> a.tracks(mediaType: "Wax Cylinder", pianist: "Brahms”)
>>> 
>>> Because to me, the 3 alternatives, especially the last one, all read
>>> more like hashmap accesses than method calls.  In other words, they
>>> make it appear as if you are passing in arbitrary keys to be queried,
>>> rather than calling one specific method.
>> 
>> I *think* I understand what you like and why you like it, but I can't
>> say I understand your rationale.  To test my understanding, what do you
>> think of this:
>> 
>>      a.tracksHaving(mediaType: "Wax Cylinder", andPianist: "Brahms")
>> 
>> ?
>> 
>> Thanks,
>> 
>> -- 
>> -Dave
>> 
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto: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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160203/4f41dbfb/attachment.html>


More information about the swift-evolution mailing list