Monday, June 9, 2008

Variable Naming Conventions

 



I use an adapted Hungarian for my PHP code. I don't know why people don't use this. When you see a variable like "$Member", you have like no clue what's inside it or how it's supposed to be used. I'm currently on a project and that's what the guy wants -- $Member -- and it's very strange to me. Anyway, here's my adapted convention:

$s + VarName = string (ex. $sVarName)
$o + VarName = object
$h + VarName = handle, like for files, SQL objects
$n + VarName = numeric (integers, floats, etc.)
$d + VarName = date or time
$b + VarName = boolean
$c + VarName = single char
$rs + VarName = recordset (rows)
$rw + VarName = record (row)

$g + above = when I have some sort of global value, which I rarely or never use

$a + above = array of whatever

$x + above = byref variable passing back value, with "x" meaning "xfer" or "transfer"

$_ + above = private variable not meant to be exposed outside the class

$a, $b, $c = iterators, with $b and $c being like nested iterators -- works better than $i, $j, $k because $i and $j almost look like each other when tired

Exception -- private variables meant to be exposed outside the class usually don't have a prefix, like .FirstName, .LastName, etc.

No comments: