Re: [CFV] how to mark protected items?

From: Date: Tue, 22 Jun 2004 11:56:54 +0000
Subject: Re: [CFV] how to mark protected items?
References: 1 2 3 4  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-31083@lists.php.net to get a copy of this message
Lukas Smith wrote: > In Zend1 and Zend2 we document how a property/method may be accessed via > phpdoc comments. In Zend2 only code we can additionally put in a > technical barrier that prevents misuse. This effectively means that if > the user doesnt look at the documentation he is slapped with an error > (unless the error is suppressed). If I'm not mistaken, the underscores were common practice even before the PEAR coding standard came to CVS. The PEAR Installer, which was committed almost half a year before the coding standard, even uses underscores - as did I back then. If Zend1 had had PPP, the use of underscores properly wouldn't be so widely used, and we properly wouldn't have the current discussions. > Eitherway its the users job to follow the documentation and not > be surprised when undocumented things go away Well, PEAR hasn't always had the best reputation when it comes to proper documentation, so I guess quite a few users have already been surprised once or twice ;-) > (since we do require phpdoc comments the API is actually by definition > fairly well documented - atleast the @access tags make this fairly clear). Of cause the documentation should be followed, but personally I wouldn't trust a '@access public' if the name of the method/variable was prefixed with an underscore. Documentation is sometimes read, hopefully understood and often forgotten - what users remember is the names of the methods/variables they use, and how it worked last time they used it. If their product works, the user often doesn't mind what's written in the documentation; well, until something breaks! > The underscore therefore was always sort of a hungarian notation to > prevent people from stupidly not following the documentation. > So to say the underscore just screams "hey I am not public!". I couldn't have said it better myself, but as such they are generally no longer needed if Zend2's PPP are used properly. With Zend2 I'd personally look twice each time I accessed a method or variable prefixed with an underscore, since it screams for attention. I believe that seeing a prefixed underscore should (no matter all the private, protected or public variable/method stuff), trigger one thought only: "Do I really know what I'm doing here", and not "oh, that's one of my own cuties" or "oh, it's so nice that I can easily recognize my own private parts - I really like that coding darn standard"! The underscores are meant for the users, not the developers. > So argueing that it its a Zend1 thing is incorrect. If Zend1 had had proper PPP, every darn private variable and method properly wouldn't have been preceded by an underscore. I don't believe that the use of underscores is bad form - on the contrary, and I never said that it was a Zend1 only thing. I even wrote that the underscores could come in handy in Zend2 (as a "hey I am not meant to be public, but I have to!" etc.). The underscores are a splendid way of 'hiding' private stuff when PPP isn't implemented. To make my self perfectly clear, I believe that the underscores should be kept at a minimum (be avoided when alternatives exist), and not used when it's not necessary, and certainly not be a requirement because of some old private habits! Regards, Heino

« previous php.pear.dev (#31083) next »