ustwo / objective-c-style-guide

The ustwo Objective-C style guide
20 stars 5 forks source link

Private Methods #7

Open martinstolz opened 10 years ago

martinstolz commented 10 years ago

The style of private methods is incorrect. Pragma marks should not be used to separate public and private methods but separating logical pieces of code.

Also it makes sense to mark your private methods in order to see immediately the purpose and membership of the method.

I have seen a proposal in Matt Galloway's book - (void)p_didLogin

Another proposal of me is using the app's prefix - (void)us2_didLogin

alexfish commented 10 years ago

:thumbsup: the private pragma never really made sense to me, as you say they separate logical pieces of code irrespective if they are private or public.

using the p_ prefix may be better as it isn't tied to an application prefix so allows for re-use.

KATT commented 10 years ago

How about a simple _-prefix? That's how it's usually approached in JS.

martinstolz commented 10 years ago

@KATT This is occupied by Apple and should not be used. See their docs.

KATT commented 10 years ago

Ah yeah, I thought that was the case, but didn't bother to google it. :)

martinstolz commented 10 years ago

:smiley:

KATT commented 10 years ago

How about __?

KATT commented 10 years ago

Otherwise, +1 on p_.

martinstolz commented 10 years ago

Same with double underscore. I use it personally! But might clash with Apple's stuff as well.

alexanderustwo commented 10 years ago

Well, we've already been through this discussion when we set up the guidelines document and the outcome of that (very long) discussion was that we should not use prefixes of the private methods in general. So the format is not wrong in the guideline.

I believe we also agreed on using the us2_ prefix when releasing e.g. open source software components to decrease the risk of accidental method overrides by the users of that component.

And regarding the pragma marks, this is also what we agreed on. We're sorting methods based on functionality, but within that group of methods we'll sort public methods first, and then have a "private" pragma mark delimiter. So that section of the style guide isn't incorrect either.