Variable Naming - NOT BORING
Posted: Fri Sep 16, 2011 9:43 pm
Hi all
just thought I would give you a little insight into the exiting world of variables!!!!
Firstly ensure you use:
Enable Explicit
This forces you to declare variables before use...pain in the rear?? Only in the short term!
Anyone reading this at some point has read some boring text on Naming Conventions for variables....So boring...but hold on..just read on a little before you dive out!
If you are coding something quick and small, say less than 1000 lines and in one file this may seem overkill but pay heed...when you are coding a project which spans several larger files this is super 'd' duper helpful in my humble opinion:
Okay so we all have been told to name our variables something useful and meaningful for easy reading and clarity. for example instead of having a variable named x which refers to a counter into a loop of sprites/lines/whatever....name it something useful such as CounterX. Yeah Yeah common sense I hear you shout...but wait it also makes sense, for clarity, to state what type this variable hold, this goes on to be CounterX.i.
On top of this I would also suggest that you could use the following conventions:
Global Variable: Add a 'g' at the beginning
Protected Variable: Add a 'p' at the beginning
So if we had a global counter as above it would be declared:
Global gCounterX.i
referred to in code later as:
For gCounterX.i = 0 to 100.....
This, although on the surface is really mundane and boring, when you project grows and you add code tested elsewhere or on its own, this kind of convention starts being super useful in debugging...trust me, going through 5000 lines of code split into different files to find that a loop, pointer, sprite position etc is using a global variable for some purpose rather than a protected one, is more boring an painful than implementing this!!
Just a little helper really!
just thought I would give you a little insight into the exiting world of variables!!!!

Firstly ensure you use:
Enable Explicit
This forces you to declare variables before use...pain in the rear?? Only in the short term!
Anyone reading this at some point has read some boring text on Naming Conventions for variables....So boring...but hold on..just read on a little before you dive out!
If you are coding something quick and small, say less than 1000 lines and in one file this may seem overkill but pay heed...when you are coding a project which spans several larger files this is super 'd' duper helpful in my humble opinion:
Okay so we all have been told to name our variables something useful and meaningful for easy reading and clarity. for example instead of having a variable named x which refers to a counter into a loop of sprites/lines/whatever....name it something useful such as CounterX. Yeah Yeah common sense I hear you shout...but wait it also makes sense, for clarity, to state what type this variable hold, this goes on to be CounterX.i.
On top of this I would also suggest that you could use the following conventions:
Global Variable: Add a 'g' at the beginning
Protected Variable: Add a 'p' at the beginning
So if we had a global counter as above it would be declared:
Global gCounterX.i
referred to in code later as:
For gCounterX.i = 0 to 100.....
This, although on the surface is really mundane and boring, when you project grows and you add code tested elsewhere or on its own, this kind of convention starts being super useful in debugging...trust me, going through 5000 lines of code split into different files to find that a loop, pointer, sprite position etc is using a global variable for some purpose rather than a protected one, is more boring an painful than implementing this!!
Just a little helper really!
