Results 1 to 7 of 7

Thread: .NET naming conventions

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2006
    Location
    Between Try & Catch
    Posts
    249

    .NET naming conventions

    I wanted to ask this question before I went further in the development process. I ask now, because someone told me I was doing it wrong.

    One of the things I carried over from VB6 was the Hungarian notation. To me, it just makes things look much cleaner when you're reading someone's code.

    So, is this still standard practice, or should I drop the prefixes? Please note, I'm only talking about variable declarations (strVariable, intVariable, etc.). I'm staying with the control conventions (txtTextBox, ddlDropDownList, etc.) until someone threatens to set me on fire for doing so.

    I'm thinking it was used alot in VB6 because it didn't have the advanced intellisense that Visual Studio has.
    If my post helped you, please rate it!

    Languages: VB/ASP.NET 2005, C# 2008,VB6
    Databases: Oracle (knowledge not currently in use), DB2

    FROM Customers
    WHERE We_Know_What_We_Want <> DB.Null
    SELECT *
    0 rows returned

  2. #2
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: .NET naming conventions

    It depends, hungarian notation was not developed for that purpose. It was actually developed to show the state of different variables like cleanDataAdaptor, dirtyDataAdaptor. www.joelonsoftware.com has more on it I belive.

    Having said that I do it with controls but not variables.

    There is no right or wrong really.

  3. #3
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: .NET naming conventions

    I just want to add also. Alot of places will have their own naming conventions in house and some have none. One of the chief principals I learned regarding variables was to declare close to where I use them. This means that I usually do not need to have any sort of naming convention for them as the declaration is never far from the usage point.

    Ive only noticed issues in other peoples code when it started to sprawl which it should not do in the first place. Good code is easy to read naming convention or not and may not even need comments as it is self explanatory.

  4. #4
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: .NET naming conventions

    Quote Originally Posted by Blakk_Majik
    ...I'm thinking it was used alot in VB6 because it didn't have the advanced intellisense that Visual Studio has.
    Sorry but that is laughable.
    "Hungarian notation" aka "Apps notation" was created long before there was VB (any version at all).
    Major advantage of that technic was for languages that didn't have any data types - programmer could recognize variable "type" by simply adding prefix (str, int, etc).
    Back then (some 30 years ago) it was a big deal tough...
    Unfortunately "Hungarian notation" became industry standard - I'm saying "unfortunately" because it got to a point when it was mandated to be used by absolutely stupid management (basically people who had very little to do with programming at all).
    Also, lots of people got into a habit of using prefixes... That's the short story behind it.

    At any rate however, naming variables should at least make some sense - don't name them a,b,c or aa, ab, ac - make it meaningful (something like oldCustomer, newCustomer, etc)...

  5. #5
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    Re: .NET naming conventions

    This is the article I was referring to: http://www.joelonsoftware.com/articles/Wrong.html

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: .NET naming conventions

    Quote Originally Posted by Blakk_Majik
    I wanted to ask this question before I went further in the development process. I ask now, because someone told me I was doing it wrong.
    Yeah, me too and me too.

    I still use it...

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: .NET naming conventions

    I dropped the Hungarian then .NET came out. When I joined this company there were very loose 'general' conventions but over time, we simply got the Microsoft recommended guidelines as our standards.

    http://msdn.microsoft.com/en-us/library/ms229002.aspx

    For the controls, the conventions are vaguer but what I use now is something like this

    TextBoxFirstName
    DropDownListCountries

    It's pseudo-Hungarian in a way, isn't it? But they're capitalized because they're effectively public properties and at the same time it helps in intellisense if you have several textboxes on the form.

    I'd say you should drop the prefixes. Others say that 'good code is readable' and so you shouldn't need the prefix to indicate the type but I don't see the point of that either. I don't think it matters what the type is, just make it something logical that indicates what it's doing in the code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width