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.
  • V Vikram A Punathambekar

    Chris Maunder wrote:

    memberId

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

    Cheers, Vıkram.


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

    C Offline
    C Offline
    Chris Maunder
    wrote on last edited by
    #11

    Yeah, I'm still trying to decide on this one. "ID" is the more common everyday form but they have a point that it's not actually an acronym.

    cheers, Chris Maunder

    CodeProject.com : C++ MVP

    O V P B 4 Replies Last reply
    0
    • V Vikram A Punathambekar

      Chris Maunder wrote:

      memberId

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

      Cheers, Vıkram.


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

      O Offline
      O Offline
      originSH
      wrote on last edited by
      #12

      IIRC the guidlines say that only TLA's or larger should have the following letters lowercase i.e. ID is fine, UID should be Uid So I'm not sure why FxCop is mouthing off aobut that one.

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

        R Offline
        R Offline
        Rama Krishna Vavilala
        wrote on last edited by
        #13

        I can guarantee that most of the code which claims that it uses Hungarian notation does not, in fact, do it correctly. I think most of the code just uses some type based prefix (may or may not in line with actual Hungarian notation). So the real debate is whether to use type based prefix or not (and not whether to use Hungarian notation or not). That being said I think a programmer should follow the notation/convention most appropriate for the platform/framework he is developing on. If I am developing in Java, I follow the java conventions (lower case everywhere except for class names). For C#: Framework Design Guidelines[^]. For JavaScript: something similar to Java. For VB/VBSCRIPT: Visual Basic naming conventions (Capital variable names). Also if your company has its own naming convention follow that. Fighting over which naming convention is better is useless. Another thing to note about .Net/Java is that properly written method/function code generally are really small. [My personal rule (based on Martin Fowler's book) is anything above 20 lines of code should be refactored and I have been pretty successful most of the times.] Which eliminates need for type based prefix notation. -- modified at 10:11 Monday 30th July, 2007

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

          G Offline
          G Offline
          Gary Kirkham
          wrote on last edited by
          #14

          John Simmons / outlaw programmer wrote:

          more natural english-like

          Looks like the Negus has infiltrated Microsoft.

          Gary Kirkham Forever Forgiven and Alive in the Spirit He is no fool who gives what he cannot keep to gain what he cannot lose. - Jim Elliot Me blog, You read

          B 1 Reply Last reply
          0
          • M Marc Clifton

            I was never into Hungarian Notation to begin with, but... Look at C# 3.0's "var" keyword. Examples here[^] about 1/2 down. I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer. Now, from what I've heard from others, the var keyword is really just a convenience for not typing in the complete type (which I disapprove of), but I suspect there are better uses. Marc

            Thyme In The Country
            Interacx
            My Blog

            R Offline
            R Offline
            Ray Hayes
            wrote on last edited by
            #15

            Easily solved with "thou shalt not use 'var'".... oopps, fallen into "Coding Standards" writing mode where usually the worst coder ends up writing the standards because they're no good at actually writing code. As a result, the rules are based on rubbish guidelines that have been cut and pasted since 1970. ;-) When I used the "var" keyword in my trial with .net 3.5 six months back (in the Orcas Preview), I found that I didn't need Hungarian Notation as the variable of type var was usually initialised only a couple of lines before it was used and generally I never kept it in scope for long. It was easier to stick with the style (non-Hungarian) used in the rest of the code. As an aside, I still find it annoying to writing variables including the type, such as "findButton" (especially as the IDE almost wants me to write "buttonFind" despite the C# naming advice from Microsoft) but yet I can't seem to come up with a cleaner standard.

            Regards, Ray

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

              O Offline
              O Offline
              originSH
              wrote on last edited by
              #16

              I use hungarian notation as a memory aid. Combined with intelligence it really speeds things up for me. i.e. what did I call that damn bool? keystrokes "this.b_" ahhhh there it is. I also use it to differentiate between local, private and public members. Local ones i use purely camelCasing, private have hungarian and public have properized (or whatever the programming term is). i.e. localVariable this.s_PrivateMember this.PublicMember It means I can quick tell where something has come from and with the private members allows me to quickly find a certain type. I combine that with always including "this." or "base." so that I also know if something is in this class or coming from an inherited class. I know alot of this isn't to many peoples tastes but it works for me, it allows me to quickly reabsorb the meaning of code I haven't visited in a while.

              R 1 Reply Last reply
              0
              • V VonHagNDaz

                I've been at my Job(1st since graduating college), for about a year now, and I dont know what I'd do without the notation. I'm mostly dealing with code that has somewhere along the lines of 10000 line functions. Having to scroll up to check types for variable types only used once would be beyond a pain in the a**. So hurray for Hungarian Notation for saving me precious time and facilitating my laziness to scroll up.

                [Insert Witty Sig Here]

                A Offline
                A Offline
                Al Beback
                wrote on last edited by
                #17

                VonHagNDaz wrote:

                So hurray for Hungarian Notation for saving me precious time

                Until the day when someone forgets to rename a variable after changing its type. ;P How often do you really need to know a variable's type? For me it's not often. When I need it, I just hover over the variable with the cursor (inside the IDE).


                Whenever an appliance, gadget, or other kind of technology you own breaks or stops performing, pray to Science for it to be saved (fixed). If it doesn't change, don't worry... just keep praying. Science works in mysterious ways! - Someone on the Internet

                1 Reply Last reply
                0
                • M Marc Clifton

                  I was never into Hungarian Notation to begin with, but... Look at C# 3.0's "var" keyword. Examples here[^] about 1/2 down. I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer. Now, from what I've heard from others, the var keyword is really just a convenience for not typing in the complete type (which I disapprove of), but I suspect there are better uses. Marc

                  Thyme In The Country
                  Interacx
                  My Blog

                  A Offline
                  A Offline
                  Al Beback
                  wrote on last edited by
                  #18

                  Marc Clifton wrote:

                  I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer.

                  Unnecessary that is. Use the IDE, Luke. :)


                  Whenever an appliance, gadget, or other kind of technology you own breaks or stops performing, pray to Science for it to be saved (fixed). If it doesn't change, don't worry... just keep praying. Science works in mysterious ways! - Someone on the Internet

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    I was never into Hungarian Notation to begin with, but... Look at C# 3.0's "var" keyword. Examples here[^] about 1/2 down. I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer. Now, from what I've heard from others, the var keyword is really just a convenience for not typing in the complete type (which I disapprove of), but I suspect there are better uses. Marc

                    Thyme In The Country
                    Interacx
                    My Blog

                    S Offline
                    S Offline
                    Steve Hansen
                    wrote on last edited by
                    #19

                    var is a keyword for the compiler to identify the type for you: var x; // Compile error var x = 10; // x is an int var x = null; // Compile error var x = "Test"; // x is an string var x = new { Name = "Test" }; // x is an anonymous type var x = from n in { "Test", "Test2" } select n; // x is an IEnumerable<string> I'll find it very useful for generics: var dict = new Dictionary<int, string>(); Dictionary<int, string> dict = new Dictionary<int, string>(); Don't think the second line tells you any more then the first. Oh, and don't forget, it can only be used as a variable, not for fields.

                    1 Reply Last reply
                    0
                    • C Chris Maunder

                      Yeah, I'm still trying to decide on this one. "ID" is the more common everyday form but they have a point that it's not actually an acronym.

                      cheers, Chris Maunder

                      CodeProject.com : C++ MVP

                      O Offline
                      O Offline
                      originSH
                      wrote on last edited by
                      #20

                      Identification Data :P

                      V 1 Reply Last reply
                      0
                      • C Chris Maunder

                        Yeah, I'm still trying to decide on this one. "ID" is the more common everyday form but they have a point that it's not actually an acronym.

                        cheers, Chris Maunder

                        CodeProject.com : C++ MVP

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

                        Chris Maunder wrote:

                        they have a point that it's not actually an acronym

                        1. I try to go with natural language. 2. Somebody here said ID stood for Identifying Datum. :~

                        Cheers, Vıkram.


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

                        B 1 Reply Last reply
                        0
                        • M Marc Clifton

                          I was never into Hungarian Notation to begin with, but... Look at C# 3.0's "var" keyword. Examples here[^] about 1/2 down. I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer. Now, from what I've heard from others, the var keyword is really just a convenience for not typing in the complete type (which I disapprove of), but I suspect there are better uses. Marc

                          Thyme In The Country
                          Interacx
                          My Blog

                          J Offline
                          J Offline
                          jbarton
                          wrote on last edited by
                          #22

                          There are much better uses for var than the just for lazy programmers. One good example of where it will help is with the new LINQ support. LINQ allows the generation of new data types as the result of a query. See http://blogs.msdn.com/danielfe/archive/2005/09/22/472884.aspx[^] for an example.

                          1 Reply Last reply
                          0
                          • O originSH

                            Identification Data :P

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

                            Damn, you beat me to it. :doh:

                            Cheers, Vıkram.


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

                            O B 2 Replies Last reply
                            0
                            • R Rama Krishna Vavilala

                              I can guarantee that most of the code which claims that it uses Hungarian notation does not, in fact, do it correctly. I think most of the code just uses some type based prefix (may or may not in line with actual Hungarian notation). So the real debate is whether to use type based prefix or not (and not whether to use Hungarian notation or not). That being said I think a programmer should follow the notation/convention most appropriate for the platform/framework he is developing on. If I am developing in Java, I follow the java conventions (lower case everywhere except for class names). For C#: Framework Design Guidelines[^]. For JavaScript: something similar to Java. For VB/VBSCRIPT: Visual Basic naming conventions (Capital variable names). Also if your company has its own naming convention follow that. Fighting over which naming convention is better is useless. Another thing to note about .Net/Java is that properly written method/function code generally are really small. [My personal rule (based on Martin Fowler's book) is anything above 20 lines of code should be refactored and I have been pretty successful most of the times.] Which eliminates need for type based prefix notation. -- modified at 10:11 Monday 30th July, 2007

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

                              Rama Krishna Vavilala wrote:

                              That being said I think a programmer should follow the notation/convention most appropriate for the platform/framework he is developing on.

                              Amen. But let's not talk about OTBS in Java

                              Cheers, Vıkram.


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

                              1 Reply Last reply
                              0
                              • O originSH

                                I use hungarian notation as a memory aid. Combined with intelligence it really speeds things up for me. i.e. what did I call that damn bool? keystrokes "this.b_" ahhhh there it is. I also use it to differentiate between local, private and public members. Local ones i use purely camelCasing, private have hungarian and public have properized (or whatever the programming term is). i.e. localVariable this.s_PrivateMember this.PublicMember It means I can quick tell where something has come from and with the private members allows me to quickly find a certain type. I combine that with always including "this." or "base." so that I also know if something is in this class or coming from an inherited class. I know alot of this isn't to many peoples tastes but it works for me, it allows me to quickly reabsorb the meaning of code I haven't visited in a while.

                                R Offline
                                R Offline
                                Rage
                                wrote on last edited by
                                #25

                                originSH wrote:

                                Combined with intelligence

                                :laugh: You probably meant IntelliSense, but some intelligence on the top of it of course does not harm. :rolleyes:

                                Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

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

                                  R Offline
                                  R Offline
                                  Rage
                                  wrote on last edited by
                                  #26

                                  <poor joke> I usually use English notation, since I do not speak Hungarian good enough to name my variables after it.</poor joke>

                                  Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                  1 Reply Last reply
                                  0
                                  • C Chris Maunder

                                    Yeah, I'm still trying to decide on this one. "ID" is the more common everyday form but they have a point that it's not actually an acronym.

                                    cheers, Chris Maunder

                                    CodeProject.com : C++ MVP

                                    P Offline
                                    P Offline
                                    peterchen
                                    wrote on last edited by
                                    #27

                                    as someone pointed out, it's an acronym of "IdentifyingDatum". :cool:


                                    We are a big screwed up dysfunctional psychotic happy family - some more screwed up, others more happy, but everybody's psychotic joint venture definition of CP
                                    My first real C# project | Linkify!|FoldWithUs! | sighist

                                    1 Reply Last reply
                                    0
                                    • R Rage

                                      originSH wrote:

                                      Combined with intelligence

                                      :laugh: You probably meant IntelliSense, but some intelligence on the top of it of course does not harm. :rolleyes:

                                      Don't follow any man spiritually, don't do anything that will get you in sh*t if god is real - Bradml[^]

                                      O Offline
                                      O Offline
                                      originSH
                                      wrote on last edited by
                                      #28

                                      whoops, yes I did, damn IESpell :P though your right the last bit needed is a dash of intelligence, otherwise computers would be able to do the coding for us :O

                                      1 Reply Last reply
                                      0
                                      • J jhwurmbach

                                        John Simmons / outlaw programmer wrote:

                                        It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names

                                        With any recent IDE, just holding the Cursor over the variable name does show the type. I cant see the point in prefixing rubbish to the name. I can cope with it, but I simply don't get the point. Maybe it is lack of practice, maybe insisting on hungarian notation comes out of lack practice reading code without it.


                                        Failure is not an option - it's built right in.

                                        J Offline
                                        J Offline
                                        James R Twine
                                        wrote on last edited by
                                        #29

                                        Yes, but until source code, diff tools and the like gain the ability to compile (or at least parse) source code to the point where they too can offer such features, there may still be a need.    There is something to be said for diff/merging a 100K+ source code file without having to keep scrolling upward just verify the type of a variable involved in a conflict.    Having the notation there does not hurt those that do not want it there (they are adults, they can ignore it), but not having it there does hurt those that need it (whatever their reasons/needs may be).    Peace!

                                        -=- James
                                        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                                        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                                        See DeleteFXPFiles

                                        1 Reply Last reply
                                        0
                                        • V Vikram A Punathambekar

                                          Damn, you beat me to it. :doh:

                                          Cheers, Vıkram.


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

                                          O Offline
                                          O Offline
                                          originSH
                                          wrote on last edited by
                                          #30

                                          ;)

                                          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