[swift-evolution] Issues with 0005-Better Translation of Objective-C APIs Into Swift

Jordan Rose jordan_rose at apple.com
Tue Feb 2 19:37:09 CST 2016


> On Feb 2, 2016, at 17:28, David Owens II via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Feb 2, 2016, at 4:54 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>>> Similarly,
>>> 
>>> let content = listItemView.text.trimming(characters: .whitespaceAndNewlines)
>>> 
>>> At least I have some context at the call site what the purpose of
>>> .whitespaceAndNewlines.
>> 
>> You wouldn't say "go to the garden and trim the plant: rhododendrons".
>> It isn't necessary for comprehension.  Why do you feel characters: is
>> necessary here?
> 
> Because unlike the English phrase, "trimming" does not have an implicit object set based on the context of a string; what else would you typically trim in a garden other than plant life? I could naturally create an API that allows trimming by a line range or string content, as an example.
> 
> "public func foo() {}".trimmed(text: "public ")
> longContentWithKnownPreamble.trimmed(lines: 0..<5)
> 
> We could make these different APIs as opposed to overloads, though I'm not convinced that they are not simply different ways to trim content.

That's actually why this one is "trimming", not "trimmed". "trimming" allows a direct object; "trimmed" does not.

I don't really have a problem with this overload set, although admittedly I can't tell if we're trimming prefixes, suffixes, or both, and I would hope that's consistent between the two.

inputText.trimming(.whitespaceAndNewlines)
inputText.trimming("public ")

These are both perfectly good noun phrases in English, too: "[get me] the inputText, trimming whitespace and newlines" and "[get me] the inputText, trimming 'public '".

(But to play David's Advocate, it also seems perfectly reasonable in English to say "[get me] the inputText, trimming whitespace and newline characters" and "[get me] the inputText, trimming the string 'public '".)

Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160202/5563c62f/attachment.html>


More information about the swift-evolution mailing list