[nycphp-talk] Length of variable names
Mark Armendariz
lists at enobrev.com
Tue Jul 3 14:01:39 EDT 2007
> From: talk-bounces at lists.nyphp.org
> [mailto:talk-bounces at lists.nyphp.org] On Behalf Of Ken Robinson
> The use of variable names like $i, $j, $k, etc for counters
> is a hold over from early Fortran which declared that only
> variables starting with certain letters could be integers.
> The first letter was "i". I seem to remember that only the
> letters i, j, l, l, m, n were used for integer variables, so
> the use quickly became a "standard" and it's been carried
> over into other languages through the use of examples written
> by old time programmers.
>
> Ken
All this time I'd thought it meant 'index' and was specifically to keep
loops short and sweet - and then j, k, etc just incrementally from index.
Thanks for info, Ken.
As for hungarian notation, I have my own similar convention that I try to
use everywhere (php, javascript, actionscript, python, etc). I picked it up
from the developers at Cuban Council in SF. A is array, I int, O is object,
etc. My own addition to their convention is to make array counts an integer
with the same name as the array:
$aEmployees = $oEmployees->getAll();
$iEmployees = count($aEmployees);
May be hard to read for some, as it probably just looks like 4 of the same
variable, but for my own internal cpu, I can see I have 3 related variables
all with their own specific purpose. It does very well for me, though
everyone has their habits for good or not.
Mark
More information about the talk
mailing list