Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Always declare private methods #42

Closed
wants to merge 1 commit into from
Closed

Always declare private methods #42

wants to merge 1 commit into from

Conversation

jackhl
Copy link
Contributor

@jackhl jackhl commented Mar 19, 2013

Recent versions of Xcode include some changes to the compiler that make it possible to invoke methods in an implementation regardless of if they are declared and regardless of the method definition order.

When I'm reading an implementation that I'm unfamiliar with the first thing I do is check the private class extension at the top of the implementation file. While it's no longer required, I feel that the benefits of having all of your methods in one place is worth it. It helps avoid leaving around abandoned methods and avoids having to initially scan through the entire implementation. Plus you can put all of your private method docs in one place.

@dannygreg
Copy link

We've had some back and forth about this internally actually.

I'm a 👍 if only for the documentation.

@jspahrsummers
Copy link
Contributor

It depends. Ideally, the purpose and usage of private methods is obvious just from the naming. That's not always true, but a declaration and documentation can easily be added when it's not – it seems like unnecessary work in other cases.

@wilmarvh
Copy link

If you don't declare it somewhere, how would you unit test private methods?

@jspahrsummers
Copy link
Contributor

We generally don't test private methods independently – only public APIs (since it's the contract with callers that's important). Of course, there are exceptions for methods that do tricky things, and it's easy enough to declare those cases too.

My point is simply that declarations can be added when necessary or helpful. I don't see why they have to be a requirement.

@supermarin
Copy link

@jspahrsummers 👍 for not testing private methods. they are private for a reason, and there are always mocking/stubbing frameworks like Kiwi for edge cases.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
5 participants