[swift-evolution] When to use argument labels (a new approach)
Matt Whiteside
mwhiteside.dev at gmail.com
Wed Feb 3 09:57:56 CST 2016
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.
Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160203/e82ba4ca/attachment.html>
More information about the swift-evolution
mailing list