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

David Owens II david at owensd.io
Tue Feb 2 18:03:22 CST 2016


> On Feb 2, 2016, at 12:48 PM, Jarod Long via swift-evolution <swift-evolution at swift.org> wrote:
> 
> This is definitely more clear when you completely separate these lines from their context, but code isn't written or read in complete isolation like this, so I think these examples significantly exaggerate the ambiguity of the pattern in the real world.
> 
> Even if you only make the minor change of renaming p to proximity (which is really what it should be), the first example becomes pretty clear:
> 
>> let next = current.updating(proximity)
> 
> 

I just want to comment on this as I keep seeing this for arguments on the lists. APIs themselves should not be relying on well named inputs into them to create clear API signatures.

The following version of the API is significantly more clear with no requirement of the variable names to be matched to the expectations of the API signature:

let next = current.updating(proximity: p)

Similarly,

let content = listItemView.text.trimming(characters: .whitespaceAndNewlines)

At least I have some context at the call site what the purpose of .whitespaceAndNewlines.

> Ultimately, I don't think this is a very difficult pattern to learn. Maybe the first handful of times you see it you'll need to read the documentation to know exactly what it's doing, but once you've seen it a few times, it's an instantly recognizable pattern. If you see a gerund method, it returns a new thing by doing the verb to the thing. Is it worth the redundancy and noise to save new developers from possibly needing to look at a method's documentation a few times?


I really do not like the -ing form; it reads backwards. I intuitively expected the object of the “trimming” to be the parameters, not the instance invoking the method.

let content = listItemView.text.trimmed(characters: .whitespaceAndNewlines)

Whereas when I read the above, it’s natural to read that the "text is trimmed with” the parameter set. The former is, “the text is trimming with” the parameter set.

-David

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


More information about the swift-evolution mailing list