Function naming in the procedural world

From: Date: Thu, 11 Jun 2009 15:56:55 +0000
Subject: Function naming in the procedural world
Groups: php.standards 
Request: Send a blank email to standards-+get-59@lists.php.net to get a copy of this message
So, lets talk standards. We have always used a modified PEAR standard for most things. One of the things we modify is function naming. PEAR states: "Global functions should be named using the "studly caps" style (also referred to as "bumpy case" or "camel caps"). In addition, they should have the package name as a prefix, to avoid name collisions between packages. The initial letter of the name (after the prefix) is lowercase, and each letter that starts a new "word" is capitalized. An example: XML_RPC_serializeData()" Now, for a repository like PEAR I can understand this. They want package information delimited by the _ and then the functions base name to use studly caps. But, in a non-OOP lib or non-repository, we found this to be very verbose and very... well... ugly. It is also counter to the (now) standards for PHP internal function naming: "Function names for user-level functions should be enclosed with in the PHP_FUNCTION() macro. They should be in lowercase, with words underscore delimited, with care taken to minimize the letter count. Abbreviations should not be used when they greatly decrease the readability of the function name itself." So, you end up with inconsistent reading code. I mean, older functions in PHP that used camel case and seemingly random variable order cause enough confusion. So, for Phorum, we use the format: {vendor}_{file}_{function}(); e.g. phorum_db_get_messages();
vendor    = phorum
file      = db (actual file name varies for db as we support several)
function = get_messages Now, this does not have a delimiter for when the function starts and the prefix ends, but I think it reads very clear and is simple to understand. I used this same scheme in Wordcraft. I used the prefix for wc_ there for brevity. Perhaps once namespaces are widespread, we can migrate to having our functions namespaced. Although, I am unclear if I can use the same namespace in several files. I know it is one namespace per file. But it is one file per namespace? Anyone know? For internal functions at dealnews.com, we skip the vendor part as it is all dealnews code. fetch_vendors(); In this case for us, the "fetch" has meaning. "get" in dealnews talk means get data from our main RDBMS and "fetch" means to get data from our forward facing replicated RDBMS pool. Poor naming choices for anyone not used to them, perhaps. How are others naming functions for internal use? -- Brian. -------- http://brian.moonspot.net/

« previous php.standards (#59) next »