In the 2017 cppcon videos, I came across a talk by Klaus Iglberger which was entitled "Free Your Functions!". In this talk, the speaker talked about how switching to free functions could easy up the process of testing private methods (See at 19:00). The idea is that you pull the private method out of the class (you make it a free function) and it becomes testable.
At first, I found the idea interesting, but then the more I thought about it, the less I understood how this is actually supposed to work. For example, let's say I have the following (dummy) class:
class SomeClass
{
public:
SomeClass();
~SomeClass();
void someTask();
private:
void someComplexTask();
void someOtherComplexTask();
};
void SomeClass::someTask()
{
someComplexTask();
someOtherComplexTask();
}
// private tasks implementations...
Then someComplexTask()
and someOtherComplexTask()
are private methods. This means that they
are implementation details, i.e. that they can only be called inside SomeClass
(or friends). It
seems to me that if you make them free functions, yes they become testable, but they are no longer
private, nor a mere implementation detail specific to SomeClass
. In fact, they can be called from anywhere in the code...
So my question is: why is Mr. Iglberger's point valid?