Can be removed the need for private methods start with underscore?
lfbn opened this issue · 5 comments
Hi there,
Don't think that starting the function name of private methods with an underscore can be useful. Can this be removed from the ruleset?
Thanks!
+1
Hi,
The public methods of any class is external API of library.
And it's really really really important to decide what information and actions have external access.
The leading underscore helps us to control that API in any place of code without documentations or IDE.
I think usually you are using publc methods of library and don't care about internal processes.
If some method become public we can rename it with IDE refactoring feature for a few seconds.
Developers in my company decided that we will use PSR Code Style with some minor fixes and check it via phpmd & phpcs with other tests. All ruleset saved to JBZoo/Misc package and you can add it to phpstorm easily.
Why do you think that undersoce is bad ? Do you have some bad practice with it ?
Thanks and best regards, Denis.
Hi,
Yes, PSR-2 disallow it:
Method names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility.
Personally I don't think is useful, and according to this thread, this practice appeared because of poor implementation of OOP in PHP4, that didn't support visibility.
Yes, I know.
I read really a lot of threads and discussions about that before making the decision.
Very quick understanding what kind of method I'm using in class (public or not) is more important that PSR. Because external API of any class is very important stuff and developer should monitor that always. Nobody cares how class works - everybody use public methods of libs.
Underscore is easy method to do it without any docs or IDE. I can just look a code!
phpmd helps to monitor it strongly.
PSR standards are just some recommendations which based on statistics. And it doesn't explain "why".
Anyway you can rename all methods in your fork and use it ;)
PS. PHP 4 died more then 10 years ago, so I never use it and don't know how it worked.
Sorry, don't think this practice is useful. You should look at the method to see what he is doing. Then you see their visibility.
Maybe I'll fork it. :) Anyway, you can close this issue if you like.