This repository has been archived by the owner. It is now read-only.

Always declare private methods #42

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@jackhl
Copy link
Contributor

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

This comment has been minimized.

Copy link

dannygreg commented Mar 19, 2013

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

I'm a 👍 if only for the documentation.

@jspahrsummers

This comment has been minimized.

Copy link
Contributor

jspahrsummers commented Mar 25, 2013

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

This comment has been minimized.

Copy link

wilmarvh commented Mar 25, 2013

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

@jspahrsummers

This comment has been minimized.

Copy link
Contributor

jspahrsummers commented Mar 25, 2013

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

This comment has been minimized.

Copy link

supermarin commented Apr 28, 2013

@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.