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

Brent Royal-Gordon brent at architechies.com
Mon Feb 8 07:37:41 CST 2016


> 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?"

Honestly, I don't think `-copyWithZone:` is a good API to use as an exemplar. It's a non-mutating method with an imperative name, which is not usually done even in Objective-C, let alone Swift. In fact, it's so unusual that it doesn't even have the same retaining conventions as most other methods.

I would consider special-casing `-copyWithZone:` to import as `copied(to:)`. (The mutable variant should be `mutablyCopied(to:)`.) `to` is used here because, when there *is* a zone in use, the new copy is made in that zone. Alternatively, you could think of the zone as an option, in which case it'd be `copied(zone:)`. Plain `-copy` should simply be hidden; it's a convenience wrapper around `-copyWithZone:`, and one that's unnecessary if the zone argument carries a default value.

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list