-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Hi Bastian,
first of all, thanks for your interesing presentation at the PHP UG Cologne last week.
Regarding the user group's discussion that night I'd like to share my point of view, too.
Short version: yes, if it's possible there should certainly be a way to make private methods accessible.
There are at least two important scenarios where this makes sense:
- CCN reduction
As a use case grows, i.e. more and more scenarios are added, the number of independent execution paths usually grows, too. This is also known as the CCN (cyclomatic complexity number, http://en.wikipedia.org/wiki/Cyclomatic_Complexity_Number): Each if, switch, etc in your code increases complexity.
Theoretically, it's OK to have a CCN of 100 - as long as you are willing to write (and maintain) 100 Test Cases for that one single function :-).
However, in the real world noone would want that, so this kind of thing is considered code smell anti-pattern "long method". A common solution for that problem is refactoring, namely refactoring pattern "extract method".
As a result the once big function will be split up into several small ones, all of which will preferably have a handy CCN of < 10. Then testing will be possible and fun again.
And as there is usually no reason to make these small functions more visible than private a testing helper like proxy-object would be really helpful if it supported private methods, too.
- Comments
Another reason to extract small methods can once again be found in Martin Fowler's classic book on refactoring:
"When you feel the need to write a comment, first try to refactor the code so that any comment becomes superflouus."
So we often extract small - and mostly private methods - with verbose names to achieve this.
Thanks again for your cool tool!
Looking forward to seeing in Cologne soon.
Andreas Czakaj
IT Director
Pixelpark AG