From: alex b. <en...@tu...> - 2001-05-14 01:13:38
|
> feel quite natural for at least a few pockets of programmers laboring in > unlabeled buildings in a few urban centers: heh > 1.) Variable and method names: mixed case with lower case leading, with > leading or trailing underscores to signify private or global. This is certainly the standard for Javascript, and indeed many other languages. > e.g. $userName seems to be favored and $_userName for a local and > "private" variables, $userName_ for global and for "public". I've never seen the latter. Though it is interesting, and would still work with the "global variable concept" I presented before. PHP Replaces the . with an _ regardless of where it is in the name. > Digression on associating private/local with leading underscore - we > read code from left to right and somehow the underscore being located to > the left seems to connote something that is more restricted or internal. I agree here. > Whereas a trailing underscore seems to imply something "further out" or > global or public. At least for many programmers I've worked with. This > seems to agree with the I don't quite agree there, but at the same time I do like the fact that it solves the "private methods vs. public variables, that's counterintuitive" problem. > 2.) Getters and setters: > > I agree with Aderhold re: getProperty() and setProperty(...) seem quite > natural. as does any other verb-noun combination: checkPermissions logIn collectGarbage etc. > It's too bad that php doesn't support function overloading, it would be > nice to be able to define setter and getter functions as: > > $obj->name_() - gets name value, name($stringVarHere) - sets name value > $obj->name_($someName_); sets the $_name property of $obj to equal > $someName_ > > It would be nice if binary cloud allowed this convention also. While I agree, I'm a little reticent to add a feature like that when I have a feeling that Zeev and friends will be adding it themselves. However, I do see the point. more thinking to do... _alex > One simple workaround to the overloading problem: > > class test > { > var $_name="not set"; > > function name_($val) > { > if(isset($val)) > $this->_name=$val; > else > return $this->_name; > } > > } > /* exercise class test */ > $obj=new test; > $tvar=$obj->name_(null); > echo "obj name is $tvar<br>"; > $obj->name_("set"); > $tvar=$obj->name_(null); > echo "obj name is $tvar<br>"; > > > > The above are just my own thoughts - I wanted to add my vote to the > discussion. Thank you. |