• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Properties: A question of style
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Properties: A question of style


  • Subject: Re: Properties: A question of style
  • From: Graham Cox <email@hidden>
  • Date: Thu, 16 Jun 2016 09:34:25 +1000

> 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


  • Follow-Ups:
    • Re: Properties: A question of style
      • From: Quincey Morris <email@hidden>
    • Re: Properties: A question of style
      • From: email@hidden
References: 
 >Properties: A question of style (From: Graham Cox <email@hidden>)
 >Re: Properties: A question of style (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: Properties: A question of style
  • Next by Date: Re: Properties: A question of style
  • Previous by thread: Re: Properties: A question of style
  • Next by thread: Re: Properties: A question of style
  • Index(es):
    • Date
    • Thread