Prefixing variables when coding

First of all i'm nearly the last person that should be writing anything about coding since a) i've only ever worked with 3 scripting languages and b) i'm self-taught, but, that said, i'm gonna do so anyway.

Poking around the web reveals a potential controversy regarding the 'correct' naming convention for variables. I've read that prefixing a variable with a letter representing its type is 'old' and out of style, one reason being that the variable type could be changed at some point. I totally disagree. I find prefixing variables with a letter representing their type to be useful, intuitive, time saving and cleaner.

If you define a variable and then access it much later, after you've forgotten what the hell it holds, well now you have go back and figure out its type. Is it an array? An integer? Where did i first use it and did i change its type somewhere along the way? And as for variables where its type is changed, that's easy to handle as well.

Here's the naming convention i use for variables:

aAnArray = an array that will always be an array
iAnInteger = an integer that will always be an integer
nFloatingPoint = a floating point that will always be a floating point
sSomeString = a string that will always be a string
vAnyType = a variable that could be any type
exeCommand = holds an executable, maybe with arguments
siStringInteger = holds a string followed by an integer
isIntegerString = holds an integer followed by a string
...and so on

One thought on “Prefixing variables when coding”

Leave a Reply

Your email address will not be published. Required fields are marked *