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

Matt Whiteside mwhiteside.dev at gmail.com
Wed Feb 3 19:07:39 CST 2016

I think this one:

	a.tracksHavingMediaType(“Wax Cylinder”, andPianist: “Brahms”)

reads better than this one:
	a.tracksHaving(mediaType: “Wax Cylinder”, andPianist: “Brahms”)

With the rationale that it would sound kind of stilted if you tried to say it out loud, and that splitting apart “tracksHavingMediaType” into “tracksHaving”… “mediaType” seems like a fairly random choice.  It could just as well be “tracks”…”havingMediaType”, where the first option only introduces the split when it must happen, at the first parameter.

I haven’t thought enough about it to see a general pattern, but that’s what I think on this particular example. HTH.


> On Feb 3, 2016, at 14:34, Dave Abrahams via swift-evolution <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> 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 <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/f8f99b85/attachment.html>

More information about the swift-evolution mailing list