[swift-evolution] [Review] SE-0005 Better Translation of Objective-C APIs Into Swift

Douglas Gregor dgregor at apple.com
Mon Feb 1 15:02:25 CST 2016


> On Feb 1, 2016, at 12:49 PM, Jordan Rose <jordan_rose at apple.com> wrote:
> 
>> 
>> On Feb 1, 2016, at 12:10, Douglas Gregor <dgregor at apple.com <mailto:dgregor at apple.com>> wrote:
>> 
>> 
>>> On Jan 29, 2016, at 12:07 PM, Jordan Rose via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> 
>>>> On Jan 28, 2016, at 14:15, Dave Abrahams via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> 
>>>>> I'm very used to "fooWithBar: baz" meaning either "get me the foo that
>>>>> has a bar matching baz" or "create me a foo with its bar set to
>>>>> baz". 
>>>> 
>>>> That's great, when that's what "with" means.
>>>> 
>>>>> But I'm not sure this new convention is any worse, now that the base
>>>>> name isn't assumed to include the first argument.
>>>> 
>>>> The problem is that, I'm guessing at least 50% of the time, "with" is
>>>> just used as a vacuous connector to make the method name sound
>>>> grammatical, and "fooWithBar" doesn't actually mean the "foo" has-a
>>>> "bar."  In these cases, it's actively misleading. I know that's not what
>>>> you were posting about, but I felt it had to be said :-/
>>> 
>>> I actually don't think this is true when "foo" is a noun (and searching through the selector dump Doug made a long time ago seems to back that up).
>>> 
>>> Exceptions:
>>> - "fooWithOptions", but that's already caught by the default parameter rule.
>>> - "fooWithLocale", which uses the locale to build the result.
>>> - "commonPrefixWithString", where the "with" isn't quite vacuous.
>>> 
>>> But when "foo" is a verb (or when it's a later parameter that's just "withBar") it does seem pretty vacuous.
>> 
>> This is a great observation. Pull request here shows what this does:
>> 
>> 	https://github.com/apple/swift-3-api-guidelines-review/pull/9 <https://github.com/apple/swift-3-api-guidelines-review/pull/9>
>> 
>> and, from the cases we’ve looked at, does a fantastic job of distinguishing the cases where “with” is a separator vs. “with” meaning some kind of selection criteria.
> 
> Oh no! Now I'm sad I added a new automated rule based on parts of speech. As I've said before, these rules are necessarily incomplete, difficult for non-native speakers, and problematic when a word can be either a noun or a verb (cf. "displayNameWithLocale(_: NSLocale) -> String" and "highlightWithLevel(_: CGFloat) -> NSColor?”).

And they are (still) most of the basis for the automatic translation described in SE-0005. Frankly, I don’t think we can avoid using parts-of-speech analysis to transform Objective-C APIs into Swift APIs.

> I'm looking at the diff but it's hard to tell what didn't change. Are there branches that differentiate the two different "with" heuristics?

The swift-3-first-argument-labels branch is the initial “with” heuristic Radek proposed. You can see the diffs between that heuristic and the “verb” heuristic here:

	https://github.com/apple/swift-3-api-guidelines-review/compare/swift-3-first-argument-labels...swift-3-first-argument-labels-verb

	- Doug


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160201/6bfe1297/attachment.html>


More information about the swift-evolution mailing list