[swift-evolution] [Discussion] API Guidelines
Dave Abrahams
dabrahams at apple.com
Sun Oct 16 14:57:28 CDT 2016
on Fri Oct 14 2016, William Sumner <swift-evolution at swift.org> wrote:
>> On Oct 14, 2016, at 8:49 AM, Adrian Zubarev via swift-evolution
>> <swift-evolution at swift.org> wrote:
>>
>> I’m still not convinced in some cases.
>>
>
>> Take a look at UIViews and its method addSubview.
>>
>> open func addSubview(_ view: UIView)
>> Personally I’d change or write this function like so:
>>
>> open func add(subview: UIView)
>> This reduces unnecessary noise _ view for both the implementation and usage.
>>
>> // Implementation
>> open func add(subview: UIView) {
>> // `subview` is descriptive and just fine here
>> }
>>
>> // Usage
>>
>> self.view.add(subview: someOtherView)
>>
>>
>>
>> --
>> Adrian Zubarev
>> Sent with Airmail
>
> This conforms to the following rule from the Argument Labels section of the naming guidelines:
>
> “[I]f the first argument forms part of a grammatical phrase, omit its
> label, appending any preceding words to the base name,
> e.g. x.addSubview(y)"
Actually, by itself that rule would allow
self.view.add(someOtherView)
But we don't do that because views aren't collections; they *have*
collections.
--
-Dave
More information about the swift-evolution
mailing list