In Depth Software Development Strategies, Tip 2: Variable Naming Conventions
Friday, 3. February 2012
The subsequent basic programming suggestion I can provide you is naming your variables appropriately. I discover that the vast majority of logic or compile mistakes are brought on by a misuse of variable names.
Here are some good examples of poor naming conventions:
1. dim newvalue as Integer
2. int x equals 0;
3. JLabel label1 equals new JLabel();
Laid out here, it is fairly uncomplicated to recognize what every single variable does, but inside a very simple plan of at the least 500 code lines it could prove instead complicated to monitor these variables.
Here are some suggestions.
In the initial case, believe about what “newvalue” represents. We know it is definitely an integer but what is it employed for? If it can be a counter for any even though loop, then how about carrying out this instead,
dim iCount as Integer
It is rather obvious that this variable is of sort interger and could be employed like a counter.
The next instance is sort in the same exact situation. a entire lot in the occasions a single letter variables are declared in C and Java, for mathmatical algorithm or for loop statements. In people instances I really feel it is completely great coding framework to utilize these variables as is. If this variable was to refer to some randomly created interger employed inside a lottery machine, then using x as that variable identify proves rather ambiguous.
In the 3rd situation JLabel label1 equals new JLabel(); on this case, you ought to be extra descriptive regarding what label1 factors to, possibly what sort of details is created from this label, or in which it is located.
If this labeled was established since the name of the program, then I would phone it JLabel lblTitle equals new JLabel();
If the labeled refered to some identify of any person I would declare it as JLabel lblName equals new JLabel();
Pretty directly forward, and these small suggestions will definitly assist you efficently analyze your code. Hungarian Notation
A handful of fast suggestions on composing your variables.
Hungarian notation is among the most typical structure styles.
iNum equals an integer value
dNum equals a decimal value
sName equals a string value
btnSubmit equals a key employed to submit
lblStudentAverage equals a label
as revealed above, make utilization of the initial original of your variable to represent what info sort it is. right here are several other examples
obj -