Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Worth including the data type in the variable name?

I'm trying to write my code as maintainable and easy to understand as possible, and I thought of including the type of data a variable holds in its name.

e.g:

$intCurrentLine = 1; instead of $currentLine = 1;
$strUser = 'blah'; instead of $user = 'blah';

I don't think it is really necessary in the above example, but may it be helpful in some cases?

  • Could this make my code more understandable?
  • Should I actually use this or stick with "normal" variable names?
  • Do you know scripts where this is used?

best regards, lamas

like image 664
lamas Avatar asked Jan 22 '10 13:01

lamas


1 Answers

Adding the type to the name of the variable is called Hungarian Notation.

It's a matter of style in typeless languages such as PHP and VB. I prefer not to use because there isn't a real need.

This is a good article on the topic. http://www.joelonsoftware.com/articles/Wrong.html

like image 193
Yada Avatar answered Sep 24 '22 04:09

Yada