Skip to content
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

Code organization: separation of private/public methods or step-down rule? #60

Closed
rhgills opened this issue Aug 31, 2013 · 2 comments
Closed
Labels

Comments

@rhgills
Copy link
Contributor

rhgills commented Aug 31, 2013

The existing organization of source files seems to consists of heavy use of pragma marks as separators, dividing methods into categories such as: initialization/dealloc and private methods.

I'm used to following the step-down rule, wherein methods are arranged such that a method definition is found below, and as close to as possible, the first method that calls it. I might annotate individual methods with comments, if helpful. For example, if overriding -(BOOL)isEqual:, I might make a note that that method is originally defined in NSObject.

The main advantages I see when following the step down rule are less jumping around the methods in an individual class and increased understanding.

Naturally, both these approaches conflict. I've rearranged the code to follow the step down rule myself when trying to understand what a particular class does and have usually left it that way after any subsequent refactorings. I feel that we should decide on one of these approaches going forward and stick to it, for consistency.

I'm also going to try and do a better job going forward matching the style of the code as I'm writing it, so you don't have to go back and fix my out-of-place formatting. I don't think Xcode has anything like this, but does AppCode support project level code style settings? For indentation and code generation and the like? I know AppCode has extensive style settings, but I seem to recall that they are global.

@jasperblues
Copy link
Member

AppCode does support a project level setting. . . Its possible to check these into the project as well, to save folks trying to match it.

I prefer to stick with the structured approach to laying out classes.

On Sep 1, 2013, at 4:31 AM, Robert Gilliam [email protected] wrote:

The existing organization of source files seems to consists of heavy use of pragma marks as separators, dividing methods into categories such as: initialization/dealloc and private methods.

I'm used to following the step-down rule, wherein methods are arranged such that a method definition is found below, and as close to as possible, the first method that calls it. I might annotate individual methods with comments, if helpful. For example, if overriding -(BOOL)isEqual:, I might make a note that that method is originally defined in NSObject.

The main advantage I see when following the step down rule is less jumping around the methods in an individual class, and I believe it helps comprehension.

Naturally, both these approaches conflict. I've rearranged the code to follow the step down rule myself when trying to understand what a particular class does, and have usually left it that way after any subsequent refactorings. I feel that we should decide on one of these approaches going forward and stick to it, for consistency.

I'm also going to try and do a better job going forward matching the style of the code as I'm writing it, so you don't have to go back and fix my out-of-place formatting. I don't think Xcode has anything like this, but does AppCode support project level code style settings? For indentation and code generation and the like? I know AppCode has extensive style settings, but I seem to recall that they are global.


Reply to this email directly or view it on GitHub.

@rhgills
Copy link
Contributor Author

rhgills commented Sep 4, 2013

Got it, structure it is.

And a project level setting sounds fantastic, I'll have to look into that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants