Re: Swift and parameter names
Re: Swift and parameter names
- Subject: Re: Swift and parameter names
- From: Charles Srstka <email@hidden>
- Date: Tue, 30 Jun 2015 17:10:54 -0500
On Jun 30, 2015, at 4:46 PM, Quincey Morris <email@hidden> wrote:
>
> 1. If the function/method being called has extremely well-known parameters, then I think I’d prefer the function to have a form that omits the names. In particular, CGRect, CGPoint and CGSize:
>
>> let rect = CGRect (x: 0, y: 0, width: 10, height: 10) // vs:
>> let rect = CGRect (0, 0, 10, 10)
>
> The point here is that the parameter semantics are known from the *name* of the function, not from the actual parameters. We have this convention already, in the default behavior where the first keyword to a regular function/method is omitted:
>
>> doSomethingWithRect (someRect)
>
>
> This is similar to the CGRect initializer case, in that we know from the name what the parameter is (because it tells us, in this case, not necessarily because we knew it in advance).
This may be true for some cases, but I disagree with this particular example. It is not at all clear what the parameters should be, simply by the name tells us it should be a rect. After all, there are multiple ways to define a rect with four numbers — the four parameters the classic Mac OS used to define a rect, for instance, were the positions of the top, left, bottom, and right edges. I’d say CGRect is definitely an instance where it seems intuitive because we’ve all been using NSMakeRect and the like for all these years, and we’re used to it.
Charles
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden