On Thu, Jan 13, 2011 at 2:23 AM, Richard Quadling <rquadl...@gmail.com>wrote:

> The Hungarian Notation [1] was what I was taught all those years ago
> when I learnt standard C programming.


I learned it early on as well, and I never really liked it. Instead of
$iFish I would prefer a more descriptive name such as $fishCount. Sure, it's
a little longer to type, but it tells you what that number measures. In
today's world of objects and loosely-typed languages, a descriptive variable
name can be more important than a symbol or notation to hint at the type.

As for arrays, I always name the variable plural. And if it maps keys to
values instead of holding a list of items, I will typically name it
$foosByBar, e.g. $customersById. From that name I *know* it's array
already--no need for a prefix or special symbol.

$oPlayer, $sName, $iWidth...what's the point? The context in which the
variable is used can provide more meaning. If you stick to short
functions/methods that do one specific thing, you'll be able to tell that
$player is an object, $name is a string, and $width is an integer.

I highly recommend the book Clean Code: A Handbook of Agile
Software Craftsmanship by Robert C. Martin. [1] It has a lot of great advice
on keeping your code easy to understand, test, and maintain.

David

[1]
http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882

Reply via email to