Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can be removed the need for private methods start with underscore? #3

Closed
lfbn opened this issue Mar 3, 2016 · 5 comments
Closed

Can be removed the need for private methods start with underscore? #3

lfbn opened this issue Mar 3, 2016 · 5 comments

Comments

@lfbn
Copy link
Contributor

lfbn commented Mar 3, 2016

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!

@lfbn lfbn changed the title Can be removed the need for private start with underscore? Can be removed the need for private methods start with underscore? Mar 3, 2016
@jncampbell
Copy link

+1

@SmetDenis
Copy link
Member

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.

@lfbn
Copy link
Contributor Author

lfbn commented Mar 6, 2016

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.

@SmetDenis
Copy link
Member

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.

@lfbn
Copy link
Contributor Author

lfbn commented Mar 7, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants