Re: Getting rid of "underscore for private method names" codingstandard
| From: | Greg Beaver | Date: | Sat, 16 Jan 2010 16:05:32 +0000 |
| Subject: | Re: Getting rid of "underscore for private method names" codingstandard | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-53217@lists.php.net to get a copy of this message | ||
Christian Weiske wrote:
> Hello all,
>
>
> I refer to http://pear.php.net/manual/en/standards.naming.php
>
> Time has come to get rid of the "Private class members are preceded by
> a single underscore" rule. There are several reasons for that:
>
> 1. PHP5 has visibility modificator support (public, private, protected)
> 2. Having an underscore preceding private methods and class variables
> makes it impossible to open up the API without breaking existing
> code.
Hi,
This assertion is untrue because by definition private methods/variables
are only used internally and are not a part of the API, thus they can be
changed/renamed at will using a search/replace with no consequences. If
one wants to expose a previously private variable or method, as far as
external users are concerned, this is no different than adding a new
variable or method.
However, I think a *far* better suggestion would be to forbid the use of
the private keyword unless the intention is to prevent any possible
modification because of race conditions or other critical coordination
issues. Instead, we require all variable to be protected or public
unless there is extreme justification. In my experience working with
other people's code, the "private" keyword simply makes it impossible to
implement code reuse without resorting to vast swaths of cut/paste.
This will have the side effect of doing the exact naming suggestion
you've made, since the current CS forbids _naming with protected
variables/methods.
Greg