Dim X As X

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
Is it good programming practice to declare a variable with the same name as the name of the class it belongs to? i.e.

Code:
Dim Employee as Employee

I suppose if you use a different name you can use the class name to get a drop down showing just the shared methods and properties, which is a small argument against doing this. Otherwise, are there any issues?
 
Possibly poor practice, but not significantly

Personally I believe reusing a type name as a variable name isn't particularly good practice, as I feel it is possibly confusing without providing much, if any, benefit. This is supported by the fact that some languages will not allow variables to be declared in this way.

However, I can think of many worse coding ills so wouldn't worry about it too much.

Good luck. :cool:
 
Re: Possibly poor practice, but not significantly

I'm not specifically for or against it, but I do find myself doing it once and a while when it seems to make sense. Since I usually code in C# the casing is different and technically there is no ambiguity.
 
Back
Top