vb.net and Hungarian variable Naming Convention

there’s a funny thing about standards and conventions. in my first programming course, the teacher gave us a list of “standard” naming prefixes… then we get to the book’s code (printed) which was completely different… often using 2-char prefixes which both our teacher and the author had said not to do. and then we get to the book’s code (digital file) which had yet again another version for naming prefixes.

in the end, we had (here’s just a few as an example (I might also be adding in a few that I’ve run across since))

  • for boolean: b, bl, bln, boo, bol
  • for dropDownLists: ddl, dd, cmbo, cbo, cbx
  • for textbox: txt, tx, tb, tbx

that’s just insane. even more crazy is that so many .net programmers can’t tear themselves away from using Hungarian prefixes. even Micro$oft says “Do not use Hungarian notation.

I use underscores for private field _names and I do use the following (only) Hungarian prefixes: txt, lbl, btn.

I like the underscore for private fields a lot:

  • it groups well in intelisense,
  • it doesn’t get in the way of reading the field name visually,
  • and it distinguishes the private name from the public property.

I could easily give up the lbl as I rarely ever refer to labels within code… and I generally only name labels unless I know that I’m going to refer to them in code. and the ONLY reason I use any of the other prefixes is to group in intelisense… which I wish I could/would stop doing.

kick it on DotNetKicks.com

3 Responses to “vb.net and Hungarian variable Naming Convention”

  1. HdDvdNet Says:

    There is practically no good reason at all why not to use Hungarian Naming conventions besides just being lazy and worried about having to type 2-3 additional letters.

    Intellisense is meant to help but for the most part programmers should not have to hover a mouse over every word to find out what it is.

    Your worried about eliminating lbl for a label prefix, why… Isnt your code cleaner being able to look at it and instantly know it is a label? Are you worried about the additional typing of bits of space those extra letters take up…

    Common sense tells us as programmers to keep our code as neat, clean and readable as possible. Eliminating prefixes for intellisense does not accomplish this.

  2. hobbylobby Says:

    My main reason for disliking the prefixes is that it makes actually reading the variable names more confusing.

    I end up reading the (often) unpronounceable prefix first, which slows my comprehension of the overall code since it invariably forces me to read slower (due to the extra brain work).

    … I’m serious about that. There have been countless brain studies which prove that the brain simply can’t take in information as fast as it is accustomed to when certain screwy things happen with written language.

    or, just chalk it up to difference in preference.

  3. hobbylobby Says:

    soeThank rkrYou namHdDvdNet, krfFor sauPosting vveYour vjrThoughts qjkAbout zmbLoving aoyHungarian wdiNaming xjqConventions.

    resI’m apoSorry, iasBut eyeI empJust negDon’t resAgree.

    hlHobbyLobby


Leave a Reply