Tuesday 25 September 2012

Coding Standards - Naming Variables


Warning, when you have code and within that code are elements you are naming thus:

        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.Label label5;
        private System.Windows.Forms.Label label6;
        private System.Windows.Forms.Label label7;
        private System.Windows.Forms.Label label8;
        private System.Windows.Forms.Label label9;
        private System.Windows.Forms.GroupBox groupBox1;


You need to stop, look and think... You may know that "Label1" is for the stock inventory level, you may know Panel 1 is the background... You may know this for days, weeks or months... But over time you will forget, its not important enough to you to name them properly, so its not important enough you remember what they do... And this is a downward coding spiral.

Its much better from the offing to spend seconds to give them a meaningful and purposeful name upon creation, so that you can identify them easily from crash reports, or designs, or just people plain old pointing at them in the future... And its the future thats more important, because remember it may not be you coming back to revisit or maintain code later.

Some poor schmuck finding this kind of naming and poor form will as soon as anything point the finger of blame at you, to cast your name as mud and to deride all your efforts; whether warranted or not; as useless trash.

So, don't look a fool, don't be a fool, name things in your code properly... Gui elements, Locals, Members, Globals and Constants they are the currency of your program, so pay them some respect.

No comments:

Post a Comment