Re: [CFV] how to mark protected items?
| From: | Justin Patrin | Date: | Tue, 22 Jun 2004 18:50:17 +0000 |
| Subject: | Re: [CFV] how to mark protected items? | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-31100@lists.php.net to get a copy of this message | ||
Bertrand Mansion wrote:
Justin Patrin wrote:I know what protected means. It's still an internal variable (internal meaning outside code shouldn't / can't access it) and IMHO should be marked as such.I am firmly in favor of _. It's *one more* character that makes the code much more readable and understandable without having to always be looking at the docs. Personally, these kidns of small hints make reading, debugging, and writing code much more enjoyable.May I suggest 2 things: 1. Learn what protected means.
2. Start writing PHP5 code.I've extensively in C++ and some in Java, as well as other OOP languages. In the beginning I found underscores annoying, but that was because I was only working with my own code. Now that I have to read others' code, I like to have the hints.
At stage 2, you will notice that most of your variables will be protected. Then you will think "Wow, that's a lot of underscores!".It's for readability. An underscore isn't all that bad.
Then, in your subclasses, you will start to ask yourself "Is this var protected or private, I can't remember".And if there is no underscore or only an underscore for private, then you'll still ask yourself: "is this protected or public, I can't remember". I understand what you're saying, but I still think it's useful to have an obvious distinction between internal and public variables. At the very least, private members should have an underscore. Protected members still can't be accessed form outside of the class, so IMHO an underscore is still useful as it tells the user-developer (with a single look at the member's name) that they can't / shouldn't use the member. -- paperCrane <Justin Patrin>