Re: Coding standard proposal

From: Date: Sat, 19 Apr 2008 16:33:05 +0000
Subject: Re: Coding standard proposal
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-49820@lists.php.net to get a copy of this message
Dmitri wrote: > Hello! > I am not a pear developer, just a heavy user of PEAR classes Good to hear. > I think it will be a good idea to add some simple coding standard for > variable naming. > > hint a variable type in the first 2-4 letters of the variable > prefixes: > string: str > array: arr > object: obj > integer: int > boolean: bool > handle: hdl > function: fn Bad idea. Clutters code, makes variable names longer, and PHP is a loosely typed language. "$intTax = $arrTaxRate[$strState] * $boolApplicable;" is completely possible, but doesn't help understand the code a single bit more with "type hints". > Follow the prefix with the CamelCase name of the variable, which should > be descriptive > For example $arrFormData or $strFileName or $boolNotify > > This will make it a lot easier to understand the code. Also > phpDocumentor code can be modified to make use of this naming convention > to automatically guess the type of variable, > for example if it sees a function like this fnParseEmail($strRawMessage, > $boolExtractAttachment = false) > it can automatically add this to doc block > @param string $strRawMessage > @param boolean $boolExtractAttachment > > I think adapting this standard will further improve the quality of pear > classes and make it easier for users of these classes to understand the > intentions of the developer of the class. Hungarian notation has been abused enough, and always for the wrong purpose. There ARE valid reasons to use it, but this one is most certainly not the case. http://www.joelonsoftware.com/articles/Wrong.html But keep on using PEAR anyway :-D -Philippe

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