[swift-evolution] When to use argument labels (a new approach)
Dave Abrahams
dabrahams at apple.com
Wed Feb 3 16:34:19 CST 2016
on Wed Feb 03 2016, Matt Whiteside <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> 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
More information about the swift-evolution
mailing list