Re: Properties: A question of style
Re: Properties: A question of style
- Subject: Re: Properties: A question of style
- From: email@hidden
- Date: Thu, 16 Jun 2016 08:47:31 +0900
Watch the Ali Ozer video from the other day at wwdc.
He covers this very topic.
Sent from my iPhone
> On Jun 16, 2016, at 8:34 AM, Graham Cox <email@hidden> wrote:
>
>
>> On 16 Jun 2016, at 3:45 AM, Jens Alfke <email@hidden> wrote:
>>
>>
>>> On Jun 14, 2016, at 4:48 PM, Graham Cox <email@hidden> wrote:
>>>
>>> @property (readonly) BOOL isFoo;
>>>
>>> or:
>>>
>>> @property (readonly, getter=isFoo) BOOL foo;
>>
>> Are you asking whether it’s better to name a boolean property “foo” or “isFoo”?
>
>
> Yes, but for readonly properties only, where there is no setter.
>
> If the property is ‘isFoo’, then in every situation (such as KVO, or using dot syntax) I would be using the keypath “isFoo”, and that’s fine, but it’s inconsistent with other properties that are not readonly, where the underlying property is ‘foo’, but in some code I’d use ‘isFoo’ and other times I’d just use ‘foo’. However, if I try and make that consistent, by having the property ‘foo’ and a custom getter ‘isFoo’, then for a readonly property it seems a bit redundant.
>
> I suppose what I’m really asking is what requires the least parsing by a developer - if I have a mix of styles, then I’m going to have to check every one to see whether there’s a custom getter or not. Better would be to stick to one style or the other, so that given a BOOL property, I know immediately how to use it without further ado. To that end, I think the second form is the most consistent, at the expense of some redundancy, but perhaps just naming BOOL properties ‘isXXX’ sidesteps that question altogether, even for readwrite properties. I can’t decide what is best practice, hence I asked the question to see what others’ opinions are.
>
>
> ―Graham
>
>
>
> _______________________________________________
>
> 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
_______________________________________________
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