[swift-evolution] When to use argument labels (a new approach)

Dave Abrahams dabrahams at apple.com
Thu Feb 4 02:05:33 CST 2016


on Wed Feb 03 2016, Matt Whiteside <mwhiteside.dev-AT-gmail.com> wrote:

> See my response down below
>
>> On Feb 3, 2016, at 17:32, Dave Abrahams via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>> 
>> on Wed Feb 03 2016, Matt Whiteside <swift-evolution at swift.org> wrote:
>> 
>>> I’m in agreement with what Ricardo is saying here:
>>> 
>>>> I personally like it and I agree with all except the following:
>>>> 
>>>> let p = someFont.glyph("propellor")
>>>> let p = someFont.glyphWithName("propellor”)
>>> 
>>> To be more specific, this example looks good to me:
>>> a.transitionToScene(.GreatHall)               // yes
>>> 
>>> but this one:
>>> let p = someFont.glyph("propellor")           // yes
>>> 
>>> somehow doesn’t.  Maybe because it reads more like subscripting a
>>> dictionary.  As a result, I think this second example kind of detracts
>>> from this section of the guidelines.
>> 
>> I wonder if it looks better written like this?
>> 
>>  let p = someFont.glyph("LATIN SMALL LETTER A WITH ACUTE")
>> 
>> "propellor" was the argument in an example of this method in use that I
>> could find on the web, but it's a really odd way to spell that word.
>> Maybe it has something to do with that.
>
> I don’t think I’m understanding the difference.

If you don't see that it makes a difference, that answers my question.
It doesn't look any better to you.

> At the risk of distracting you with minutiae, this particular example
> feels more like a property access than a method call, so my mind wants
> to rewrite it as this:
>
> someFont.glyphs[“LATIN SMALL LETTER A WITH ACUTE”]
>
> and that makes it a little harder to stay focused on the intent of the guideline.

Well, I agree with you in general.  There are lots of methods in Cocoa like

      view.addGestureRecognizer(sumthin)

that would be so much better as

     view.gestureRecognizers.add(sumthin)

But since I doubt there's any way we're going to be able to
automatically make the conversion, or convert NSFont.glyphWithName into
a subscript access on a property, the question of how to write such
methods is still important.

-- 
-Dave


More information about the swift-evolution mailing list