Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- Subject: Re: Stupid Cocoa question. How can you tell if the object you are looking at is a property or an ivar?
- From: Graham Cox <email@hidden>
- Date: Fri, 22 May 2015 09:36:35 +1000
> On 22 May 2015, at 2:28 am, Alex Zavatone <email@hidden> wrote:
>
> if you use myThing, it's not visually obvious that you're directly accessing the ivar
This is where a consistent and deeply ingrained naming convention is useful. The leading underscore has always been Cocoa’s “way” of doing that, and with auto-synthesis that’s now baked in. But actually because of that, it’s less useful as a naming convention, because it puts you back to square 1 with knowing which is an ivar you added and which is a synthesised property.
Because I came to Cocoa from C++, I have long had a habit of prefixing all my ivars with ‘m’ (for ‘member’). Some Cocoa folks don’t like that idiom, but I know that any time I see an access to anything starting with ‘m’ it’s a direct member. Sometimes I do m_ which makes it stand out even more. A lot of sample code seems to encourage the use of ‘my’ for anything that’s not part of the framework, but it quickly becomes overloaded. Whatever you choose, stick to it, that’s the important thing.
(Not sure, but it might also be possible to set up syntax colouring so that ivars you declare are highlighted differently).
—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