Object Naming Conventions in VB .NET 2005

Posted on 2007-08-10
Last Modified: 2013-11-26
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
Question by:mjs082969
    LVL 48

    Accepted Solution

    I normally use the Naming Conventions for my Visual Basic project, like 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
    LVL 24

    Assisted Solution

    <<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.

    LVL 48

    Expert Comment

    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.
    LVL 24

    Expert Comment

    Same here.

    Author Comment

    It was actually Microsoft documentation (
    ) 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.
    LVL 4

    Assisted Solution

    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.
    LVL 38

    Assisted Solution

    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:


    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


    Dim bFlag as Boolean

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


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Article by: Martin
    Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now