Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Hungarian Notation in .Net - Yes or No?

Hungarian Notation in .Net - Yes or No?

Scheduled Pinned Locked Moved The Lounge
csharpc++rubybeta-testingtools
90 Posts 42 Posters 8 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Paul M Watt

    I agree with you comments about the sort of data, just not the type. I ditched Hungarian notation a while back, but I still like 'p' for pointer, and sometimes a few others. like "is" for a boolean to make the name look like a question etc...

    J Offline
    J Offline
    Judah Gabriel Himango
    wrote on last edited by
    #69

    Paul Watt wrote:

    ike "is" for a boolean to make the name look like a question etc...

    I've been doing that now as well. isFooEnabled, isDisplayingBars, etc.

    Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

    B 1 Reply Last reply
    0
    • P Paul M Watt

      I agree with you comments about the sort of data, just not the type. I ditched Hungarian notation a while back, but I still like 'p' for pointer, and sometimes a few others. like "is" for a boolean to make the name look like a question etc...

      S Offline
      S Offline
      Shog9 0
      wrote on last edited by
      #70

      Paul Watt wrote:

      "is" for a boolean to make the name look like a question

      Yeah, i'm fine with that, 'cause it can actually make the code more readable: if (isAnOddChoice), if (hasNoWhereToRun), while (noMatchFound), etc. But to me, that's just putting a bit of thought into your naming rather than picking some generic name (e.g., Success) and tacking on a prefix. Of course, i'm totally lazy enough to do the latter at every turn, so perhaps my attitude is just a desire to force myself into using better names... ;)

      ----

      I don't care what you consider witty, but at least I do not blather on posting nonsense like Jim Crafton.

      -- Stringcheese, humbled by Crafton's ability to string together multiple sentences

      1 Reply Last reply
      0
      • C Cyrilix

        That's 24 lines. Wow. I can imagine your code would be so highly componentized as to have to trace 50 layers down the call stack in order to find out what you're actually doing. I hope you're exaggerating -- to me, anywhere up to 150 lines sounds a bit more realistic.

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #71

        Cyrilix wrote:

        I hope you're exaggerating -- to me, anywhere up to 150 lines sounds a bit more realistic

        I said "you should look at refactoring it" not that you MUST refactor it. At a quick glance I can see that the vast majority of my methods fit in one screen. That would be about 30 to 40 lines.

        Cyrilix wrote:

        I can imagine your code would be so highly componentized as to have to trace 50 layers down the call stack in order to find out what you're actually doing.

        Not as far as that, but then my code reuse is way up on what it was when I wrote methods at 100+ lines. Also, I give things meaningful names so it is easy to see what something does without having to go into every method.


        Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website

        1 Reply Last reply
        0
        • M Marc Clifton

          Vikram A Punathambekar wrote:

          I use ID instead of Id. FxCop bugs the hell out of me on that one.

          Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc

          Thyme In The Country
          Interacx
          My Blog

          G Offline
          G Offline
          Gary Wheeler
          wrote on last edited by
          #72

          I despise using lower/Camel/Pascal case for an acronym. IMO, acronyms should always be upper case.


          Software Zen: delete this;

          1 Reply Last reply
          0
          • M Marc Clifton

            Vikram A Punathambekar wrote:

            I use ID instead of Id. FxCop bugs the hell out of me on that one.

            Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc

            Thyme In The Country
            Interacx
            My Blog

            P Offline
            P Offline
            Patrick Etc
            wrote on last edited by
            #73

            Matlab purists get tied up when you spell it 'Matlab' instead of 'MATLAB'. Apparently, 15 years ago each of those letters meant something and you better well recognize the acronym, dammit!

            1 Reply Last reply
            0
            • J Judah Gabriel Himango

              Paul Watt wrote:

              ike "is" for a boolean to make the name look like a question etc...

              I've been doing that now as well. isFooEnabled, isDisplayingBars, etc.

              Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

              B Offline
              B Offline
              Brady Kelly
              wrote on last edited by
              #74

              Judah Himango wrote:

              I've been doing that now as well. isFooEnabled, isDisplayingBars, etc.

              Opens up a whole new kettle of questions (I'm mixing what?). I often, late at night, get strung out over, 'isForExport', or 'mustExport', or 'useAltExport', or 'isToUseAltExport'.

              S 1 Reply Last reply
              0
              • realJSOPR realJSOP

                I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines: Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate. It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------

                M Offline
                M Offline
                Michael P Butler
                wrote on last edited by
                #75

                As an old MFC hand, when I first moved to C# - I kept up the Hungarian notation for a while, but then I started to fall into the new MS standard as it made my code fit better and more readable to the VB programmers I started working with. Of course, with the latest IDE's. Knowing the type of a variable is just a mouse hover away.

                Michael Thanks to all for your kind words and support on my return to CP. This place and you guys and gals are just the best

                1 Reply Last reply
                0
                • B Brady Kelly

                  Judah Himango wrote:

                  I've been doing that now as well. isFooEnabled, isDisplayingBars, etc.

                  Opens up a whole new kettle of questions (I'm mixing what?). I often, late at night, get strung out over, 'isForExport', or 'mustExport', or 'useAltExport', or 'isToUseAltExport'.

                  S Offline
                  S Offline
                  Shog9 0
                  wrote on last edited by
                  #76

                  Here's the trick: read the code out loud: if it comes out sounding like a bad foreign accent (or, Yoda), then you need to work on the names... ;)

                  ----

                  I don't care what you consider witty, but at least I do not blather on posting nonsense like Jim Crafton.

                  -- Stringcheese, humbled by Crafton's ability to string together multiple sentences

                  J S 2 Replies Last reply
                  0
                  • V Vikram A Punathambekar

                    :) I too went to .NET from a Win32/MFC background, and found it strange - userName instead of strUserName felt awkward at first, but now it's the other way round. Besides, if you were to continue using Hungarian, your variable names would clash savagely with the framework's names (and others' ;) ). I'll tell you what I do not like about the .NET naming conventions, though - I think camelCase is way better for method names. [ducks]

                    John Simmons / outlaw programmer wrote:

                    the ORCAS Beta 2 is so transiently reliable

                    I'd never install MS (or for that matter, most) betas. Unless the client wanted something to be oh-so-ready for the future.

                    Cheers, Vıkram.


                    After all is said and done, much is said and little is done.

                    D Offline
                    D Offline
                    David Stone
                    wrote on last edited by
                    #77

                    Vikram A Punathambekar wrote:

                    I think camelCase is way better for method names. [ducks]

                    Actually, after having spent so much time in Java over the past few quarters at school, camelCase method names feel more natural for me. I still have to think about it when I'm writing C# again.

                    V 1 Reply Last reply
                    0
                    • B Brady Kelly

                      Nemanja Trifunovic wrote:

                      brain-damaged .NET 1.x collections

                      What do you mean by that? The non-generic ones?

                      D Offline
                      D Offline
                      David Stone
                      wrote on last edited by
                      #78

                      Yes. Using non-generic collections is a horrific practice in any application that has access to the generic ones.

                      S 1 Reply Last reply
                      0
                      • P Paul Conrad

                        Chris Maunder wrote:

                        hungarian notation

                        Now that's a notation I have not used in a long, long, long time :)

                        "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                        S Offline
                        S Offline
                        StevenWalsh
                        wrote on last edited by
                        #79

                        Paul Conrad wrote:

                        Now that's a notation I have not used in a long, long, long time

                        I Float between the two, but i've lately i've been trying to double my use of hungarian notation ;)

                        P 1 Reply Last reply
                        0
                        • S Shog9 0

                          Here's the trick: read the code out loud: if it comes out sounding like a bad foreign accent (or, Yoda), then you need to work on the names... ;)

                          ----

                          I don't care what you consider witty, but at least I do not blather on posting nonsense like Jim Crafton.

                          -- Stringcheese, humbled by Crafton's ability to string together multiple sentences

                          J Offline
                          J Offline
                          Judah Gabriel Himango
                          wrote on last edited by
                          #80

                          :laugh: Seriously though, that's a great argument for fluent interfaces[^].

                          Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                          1 Reply Last reply
                          0
                          • V Vikram A Punathambekar

                            :) I too went to .NET from a Win32/MFC background, and found it strange - userName instead of strUserName felt awkward at first, but now it's the other way round. Besides, if you were to continue using Hungarian, your variable names would clash savagely with the framework's names (and others' ;) ). I'll tell you what I do not like about the .NET naming conventions, though - I think camelCase is way better for method names. [ducks]

                            John Simmons / outlaw programmer wrote:

                            the ORCAS Beta 2 is so transiently reliable

                            I'd never install MS (or for that matter, most) betas. Unless the client wanted something to be oh-so-ready for the future.

                            Cheers, Vıkram.


                            After all is said and done, much is said and little is done.

                            R Offline
                            R Offline
                            Rocky Moore
                            wrote on last edited by
                            #81

                            Vikram A Punathambekar wrote:

                            I'll tell you what I do not like about the .NET naming conventions

                            The one thing I do not like about .NET naming conventions is VB and any other case insensitive langauges forcing those bloddy "_" underscores on us again. I think that key needs to be removed from everyone's keyboard! :)

                            Rocky <>< Latest Code Blog Post: www.TheWPFDirectory.com site launched! Latest Tech Blog Post: You got to see this - Seadragon and Photosynth!

                            1 Reply Last reply
                            0
                            • J Judah Gabriel Himango

                              I don't mind Hungarian notation (the false kind that's practiced now, or the original kind[^]), which, ironically for you, was invented by a Microsoft programmer. Personally, once I started coding in C#, I abandoned all Hungarian notation and found it quite liberating. It now seems superfluous to put a character at the beginning of each variable just to define the type. Simply put, I've never once thought to myself, "gee, is it a boolean? Or a string?"

                              Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                              R Offline
                              R Offline
                              Rocky Moore
                              wrote on last edited by
                              #82

                              Yeah, I agree. Funny though, when it comes to bool's I never thought I could survive without bMailWaiting or bPosts, but after .NET it seems much clearer with isMailWaiting or hasPosts... :) Oh yeah, I almost forgot, now about every method that returns a status bool for failure, now my local variable inside the method is usually "isOkay" ;) Okay, it could be "bIsOkay", but that just doesn't sound right :)

                              Rocky <>< Latest Code Blog Post: www.TheWPFDirectory.com site launched! Latest Tech Blog Post: You got to see this - Seadragon and Photosynth!

                              1 Reply Last reply
                              0
                              • S StevenWalsh

                                Paul Conrad wrote:

                                Now that's a notation I have not used in a long, long, long time

                                I Float between the two, but i've lately i've been trying to double my use of hungarian notation ;)

                                P Offline
                                P Offline
                                Paul Conrad
                                wrote on last edited by
                                #83

                                Sometimes I'll do Hungarian out of shear laziness :->

                                "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                                1 Reply Last reply
                                0
                                • realJSOPR realJSOP

                                  I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines: Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate. It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------

                                  M Offline
                                  M Offline
                                  Michael Dunn
                                  wrote on last edited by
                                  #84

                                  John Simmons / outlaw programmer wrote:

                                  If you change the variable's type, it all of a sudden invalidates the name of the variable.

                                  This is a Good Thing. If you change the type of a variable, it's a good idea to look at every place the variable is used, to make sure the code using it is still correct.

                                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                                  1 Reply Last reply
                                  0
                                  • realJSOPR realJSOP

                                    I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines: Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate. It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------

                                    P Offline
                                    P Offline
                                    PaulPrice
                                    wrote on last edited by
                                    #85

                                    As mentioned at some point in this thread, a decent IDE will tell you a type anyway so you do not need to include this information in the variable name. Also I tend to find that if all variable names look the same, for example start with str or mint then I struggle to read the code.

                                    1 Reply Last reply
                                    0
                                    • D David Stone

                                      Yes. Using non-generic collections is a horrific practice in any application that has access to the generic ones.

                                      S Offline
                                      S Offline
                                      Stuart Dootson
                                      wrote on last edited by
                                      #86

                                      Quite right - after having used C++/STL for more years than I care to remember, I was unwilling to look at .NET at all until 2.0. And with lambdas and Linq in 3.0, C# is looking pretty good...

                                      1 Reply Last reply
                                      0
                                      • S Shog9 0

                                        Here's the trick: read the code out loud: if it comes out sounding like a bad foreign accent (or, Yoda), then you need to work on the names... ;)

                                        ----

                                        I don't care what you consider witty, but at least I do not blather on posting nonsense like Jim Crafton.

                                        -- Stringcheese, humbled by Crafton's ability to string together multiple sentences

                                        S Offline
                                        S Offline
                                        Stuart Dootson
                                        wrote on last edited by
                                        #87

                                        Careful - too far down that road and you'll turn into the Grand Magus :-)

                                        1 Reply Last reply
                                        0
                                        • D David Stone

                                          Vikram A Punathambekar wrote:

                                          I think camelCase is way better for method names. [ducks]

                                          Actually, after having spent so much time in Java over the past few quarters at school, camelCase method names feel more natural for me. I still have to think about it when I'm writing C# again.

                                          V Offline
                                          V Offline
                                          Vikram A Punathambekar
                                          wrote on last edited by
                                          #88

                                          I *have* done some Java, but it wasn't a big deal - one paper at college and one Java app maintenance at my previous company. I've written FAR more C# code than Java, but for some strange reason, camelCase feels more natural for method names. I actually dislike PascalCase for method names!

                                          Cheers, Vıkram.


                                          After all is said and done, much is said and little is done.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups