Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 232
  • Last Modified:

Object Naming Conventions in VB .NET 2005

I have just read some articles which advise abandoning the use of Hungarian notation in VB .NET.  How are most people handling this?  I kind of though it was beneficial, particularly for UI objects ('cmd' for command buttons, etc) although I do recall some situations where things got out of hand.

I am really just looking for some input, as to other developer's experience with migrating away from (or even quitting cold turkey) Hungarian notation in .NET  

Although this is kind of an 'easy' question, only someone with a great deal of experience will be able to contribute....  so I will assign a high point value and split the points between primary contributors.

Thanks In Advance,

- Michael
0
mjs082969
Asked:
mjs082969
4 Solutions
 
jpaulinoCommented:
I normally use the Naming Conventions for my Visual Basic project, like http://www.mis.uwec.edu/keys/Teaching/is304/wncNET.htm. When I say normally I mean that I use in most of the thing no all. I think that it helps allot with forms, buttons, and most of the objects. I dont use all for variables, normally only for Booleans and Strings.

The most important for me is when Im reading the code I understand easily
0
 
hesCommented:
<<The most important for me is when I'm reading the code I understand easily>>
And most importantly when someone else is reading the code, making it easy to understand. Expecially if they have to fix something(forbid we have never had a program crash)

<<I am really just looking for some input, as to other developer's experience with migrating away from>>
I my opinion whoever wrote the article has never had to modify somebody elses code.
Migrating away from , not a chance.

0
 
jpaulinoCommented:
Thats right hes, but the most important for me (and I dont leave without them) are the comments. I place them all around my code.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
hesCommented:
:)
Same here.
0
 
mjs082969Author Commented:
It was actually Microsoft documentation (
http://msdn2.microsoft.com/en-us/library/h0eyck3s(VS.71).aspx
) that advised against using Hungarian.  But perhaps I need to read further.  The documentation I have read says (so far) to avoid using Hungarian for events, properties, methods, and parameters.  

Personally, I think it makes sense to use Hungarian for UI objects such as forms and text boxes.  But I have also seen the nastiness that overzealous use of Hungarian can create.  Maybe this is the point that Microsoft is attempting to get across.
0
 
gabbadarCommented:
It really comes down to opinion. Hungarian notation was developed as a form of commenting within the code. To me, it's like making concise, uniform function names - it just helps remember what it's for. It aids with readability.

As far as .NET, using Hungarian notation within the code is less useful than it was in VB6, or other languages, but I still use it for general identification. For example rsName for record sets, strings, boolean, bitflags, short/long values, etc.. Strict use would be a hindrance in my opinion. And I'm pretty sure Microsoft still encourages Hungarian notation for UI objects.
0
 
PaulHewsCommented:
While I haven't quit cold turkey, I have moved away from a slavish use of prefixes.  

The point of HN is that looking at a variable you know what type it is supposed to be.  Well if you see code like:

ResultCount += 1

there cannot be much mistake what that is.  Similarly:

strText

is just a little bit silly (not that I haven't done that a thousand times....)  Of course one might just need to differentiate from Form.Text, in which case maybe Text isn't the best variable name anyway.

Lists, hashtables and other data structures do well to be differentiated.  I'll usually just add it to the variable name.  

Dim CustomerList as List(Of Customer)
Dim DateSentHash as Hashtable

The truth is that there are so many classes in the framework, you would be hard put to rationally prefix them all in a way that is still readable.

The prefix doesn't really matter as much as clear naming.  For example, I'll take:

Dim HasDataLeft As Boolean

over

Dim bFlag as Boolean

any day.  The first describes what the flag is for, the second, merely that it is a flag.

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now