DEV Community

Discussion on: Private methods are a code smell

 
jessekphillips profile image
Jesse Phillips

And having to search for logic in many specific classes is easier than having to look for it in hidden private methods that logically don't belong where they are.

As nice as that sounds, private methods don't actually hide logic, I just don't see myself doing a search in the way you're describing it happens.

It's weird because I agree and disagree at the same time. I generally don't think class are required for most logic, they should generally be free functions which operate on the class/data. This way your class keeps its single responsibility and you have functions with one responsibility.

Thread Thread
 
koffeinfrei profile image
Alexis Reigel

private methods don't actually hide logic.

They usually do though, which is (in my experience) the main reason for them to be private (which this post details).

I generally don't think class are required for most logic, they should generally be free functions which operate on the class/data. This way your class keeps its single responsibility and you have functions with one responsibility.

Neither do I, it heavily depends on the language you're using. A lot of languages don't require you to use classes to encapsulate logic. Using classes actually enables the use of private logic. Using functional approaches leads to treating each function as a valid public entity, generally leading to less running into the "private code smell".