Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it good programming practice to declare a variable with the same name as the name of the class it belongs to? i.e.

 

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?

Posted

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:

Never trouble another for what you can do for yourself.
  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...