New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_setup is probably a bad name for the setup method #8

Closed
orta opened this Issue Jan 1, 2013 · 11 comments

Comments

Projects
None yet
2 participants
@orta
Copy link

orta commented Jan 1, 2013

Apple's docs ask you to never underscore your methods as they reserve the namespace for objc internals.

@icanzilb

This comment has been minimized.

Copy link
Collaborator

icanzilb commented Jan 1, 2013

Never seen this, do you have a link to the particular doc page? That'll be interesting to read upon

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

Here's the doc: Coding Guidelines for Cocoa

Don’t use the underscore character as a prefix for your private methods. Apple reserves this convention.

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

You can quite safely argue that since you're subclassing an NSObject and as such it's not a problem, but it's a library and so you never can be too sure what people will do with it.

@icanzilb

This comment has been minimized.

Copy link
Collaborator

icanzilb commented Jan 1, 2013

I see ... never stumbled upon this recommendation before. It looks fine though, I can refactor the private method names at any time (i.e. with the next patch version)

@icanzilb

This comment has been minimized.

Copy link
Collaborator

icanzilb commented Jan 1, 2013

Any advice on best-private-methods-naming-convention? I believe I'll go with "JM_methodName" if you don't have anything better in mind

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

Some people ignore it, some people end with an underscore setup_, others use static functions ( I think that's how AFNetworking does it ) and yeah some people use prefixed names. You see a lot of that in categories.

Personally, I think OR_[method] prefixing is ugly. So I'd be inclined to put a double underscore at the end ( setup is a pretty common method name. )

@icanzilb

This comment has been minimized.

Copy link
Collaborator

icanzilb commented Jan 1, 2013

I personally like underscoring better as well - a double underscore at the end of the method name will be closer to what I had in mind in first place.

Although - this solution does not seem to fit all the other of my private methods, like:
-(id)_reverseTransform:(id)value forProperty:(JSONModelClassProperty*)p

If I add a double underscore just before the last argument will be definitely uglier than a "JM_" prefix.

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

Afraid so. TBH though, I would only worry about using it on generic sounding method names. For example _setupForJSONModel is significantly safer from conflicts than _setup

I guess its also safe to -(id)__reverseTransform:(id)value forProperty:(JSONModelClassProperty*)p hah.

@icanzilb

This comment has been minimized.

Copy link
Collaborator

icanzilb commented Jan 1, 2013

Alright! I'll follow coherence over recommendation.

  1. all private methods will get a double underscore prefix
  2. non-safe methods like "setup" will get an extra double underscore suffix

This should give the code a coherent look, it'll still break the Apple recommendation but not by too much.

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

👍

@orta orta closed this Jan 1, 2013

@orta

This comment has been minimized.

Copy link

orta commented Jan 1, 2013

Oh BTW, you could try using ARAnalytics instead of your Tracker library, it should do all of same stuff + some more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment