orangedog1984 — 2011-10-17T14:18:01-04:00 — #1
My supervisors' code features variable names with letters prefixed to them to indicate the variable type i.e. $iCount (for an integer for use as a counter) or $aDeck (array of results from db query about a deck of cards in a gaming application etc). I was told this is standard universal coding practice. is it?
salathe — 2011-10-17T15:46:11-04:00 — #2
No. Search "Hungarian Notation" if you want to bore yourself to sleep. :x
logic_earth — 2011-10-17T19:15:54-04:00 — #3
I think Hungarian Notation is a stupid practice in a dynamically typed language. A variable can change its type as easily as it can change its value. And adding a bunch of variables can be a lot more confusing then reusing the same variable for the same subject. Thats my opinion anyways.
force — 2011-10-17T21:05:39-04:00 — #4
It's not a practice I use, though I have seen it used occasionally in VBScript.
IMHO, it's a poor practice to use in PHP because PHPdoesn't use strict typing (like logic_earth said), and because mistakes can arise if a variable's type changes and the name no longer properly represents what it is.
It's an approach to correct the lack of strict typing in PHP...which doesn't usually end up working so well.
If you name a variable descriptively enough, you can always tell what kind of data is is supposed to store.
felgall — 2011-10-18T04:28:28-04:00 — #5
That notation only makes sense in languages that use strict typing and where the programmer is expected to have a bad memory anyd be unable to remember to look back a half dozen lines to where the variable was defined.
$iCount = 0;
if (is_numeric($iCount)) $iCount = 'nonsense'; // completely valid in PHP