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. Why the world hates Hungarian notation?

Why the world hates Hungarian notation?

Scheduled Pinned Locked Moved The Lounge
questioncsharpc++collaborationtutorial
96 Posts 54 Posters 2 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.
  • E Eytukan

    I'm about to write the coding standards doc for a team. I've been using Hungarian notation ever since I stated coding. The blogs that I read online rant against use of Hu system on OO languages, but I have few questions: Though it's C++ or C#, we do have primitive data types everywhere. In fact, for smaller projects, primitive data types would account for 90% of the variables. Now I'm dealing with a lot of nummbers , flags & so on. How do I know what datatype it is? For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home. I just open it in notepad and try to figure out what datatypes all these variables are. No where I can figure out this. Then why the heck everybody rants against this convention? I'm going ahead insisting on sticking with the Hu notion. If anybody has a valid reason against it, I'm all ears to it. (if you dont like Hu notation, please dont express it with the 1 vote here :sigh: )

    Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

    R Offline
    R Offline
    RiskFactor
    wrote on last edited by
    #85

    I would put forward a couple of reasons that Hu notation is not needed and why I do not use it. 1) All the names I assign within my objects (properties, methods, fields, etc.) derive there name based on what the business owners call it in the real world if there is a corelation. As a developer I can only do my job well when I also understand the real world objects that my code represents. As such a new developer must obtain some level of this knowledge for the data types to be evident. The example of AccountNumber in above posts should be understood within the logical context of your system. If I call a variable accountNumber then likely I have some idea of what that account number is within the context of my system. Hu notation will not tell me anything more than the common business knowledge will. The reality is that if I name it strAccountNumber all I know is that it is a string of some length. I would not be able to know simply from the "str" if the business rules allow special characters, if the max length was 8 characters, etc. 2) Modern IDE's virtually remove the need for Hu notation. If the declaration of a variable is not in view and the data type is not apparent based on my knowledge of the business domain then (as a .NET developer) all I have to do is hover over the variable and the type is immediate shown thanks to intellisense.

    1 Reply Last reply
    0
    • D Dr Walt Fair PE

      Most of the devs I know would tie it back to the data it represents and accounting systems call it Account Number, even if it might be a string. In fact my own accounting system has "Account Numbers" that include letters to differentiate types of clients. When someone calls and I ask for their Account Number, there's never any confusion.

      CQ de W5ALT

      Walt Fair, Jr., P. E. Comport Computing Specializing in Technical Engineering Software

      J Offline
      J Offline
      James Lonero
      wrote on last edited by
      #86

      Can your (human) clients differentiate between 0 (zero) an O? A l and 1?

      1 Reply Last reply
      0
      • N Nish Nishant

        Well I've got to say that between lAccNum and accountNumber, the latter clearly indicates what the type is.

        Regards, Nish


        My technology blog: voidnish.wordpress.com

        C Offline
        C Offline
        CDMTJX
        wrote on last edited by
        #87

        Is accountNumber a decimal (1234) or a string ("1234")? lAccNum, lAccountNumber, sAccountNumber, pcAccountNumber are more descriptive.

        1 Reply Last reply
        0
        • E Eytukan

          I'm about to write the coding standards doc for a team. I've been using Hungarian notation ever since I stated coding. The blogs that I read online rant against use of Hu system on OO languages, but I have few questions: Though it's C++ or C#, we do have primitive data types everywhere. In fact, for smaller projects, primitive data types would account for 90% of the variables. Now I'm dealing with a lot of nummbers , flags & so on. How do I know what datatype it is? For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home. I just open it in notepad and try to figure out what datatypes all these variables are. No where I can figure out this. Then why the heck everybody rants against this convention? I'm going ahead insisting on sticking with the Hu notion. If anybody has a valid reason against it, I'm all ears to it. (if you dont like Hu notation, please dont express it with the 1 vote here :sigh: )

          Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #88

          I used to use Hungarian notation when working in a weakly-typed language, but quickly gave it up when working with C# and .NET. It wasn't just because C# is strongly typed; it was also because of: - Property names and data binding - Mapping database table and column names to classes and ORM's - Serializing / deserializing objects to / from XML - Configuration files - Reflection. Hungarian notation might be fine if your "names" never see the light of day; in most other cases, it gets ugly and geeky really fast.

          1 Reply Last reply
          0
          • D David Roh

            Sure, we can always find difficult issues - the idea is to find ways to make our code more readable and understandable for whoever has to maintain it. My style has changed a lot over the passed 44 years of coding and it is still changing as I discover better ways of making my code more reliable and more maintainable. It's really frustrating, for example, when I am reading someone elses code that makes it impossible to tell a local variable from a class level variable - maybe that does not bother you but it does me. I certainly welcome any ideas for making my code better; however, not doing the best that I can to let the reader know about the type, scope, and usage of a variable is a non-starter for me.

            J Offline
            J Offline
            jschell
            wrote on last edited by
            #89

            David Roh wrote:

            Sure, we can always find difficult issues - the idea is to find ways to make our code more readable and understandable for whoever has to maintain it.

            Yes that is a common way to rationalize subjective preferences.

            David Roh wrote:

            It's really frustrating, for example, when I am reading someone elses code that makes it impossible to tell a local variable from a class level variable - maybe that does not bother you but it does me.

            Nope that doesn't happen to me. What does happen to me is that I get frustrated when I realize the code has no error checking. Or is ignoring part of the API Is it supposed to be interacting with. Or it is just doing something wrong with the API. Or it has some horribly inefficient design based on a piece of code that by definition must handle high volumes. And other types of problems like that. If my most serious problem or even close to most serious problem was confusion about the type of a variable then I would suspect that I had moved into an alternative reality.

            David Roh wrote:

            I certainly welcome any ideas for making my code better; however, not doing the best that I can to let the reader know about the type, scope, and usage of a variable is a non-starter for me.

            And I welcome ideas that objectively make code better. I do however realize that most ideas not not backed by anything objective. I also recognize as well that vast majority of development problems do not have anything to do with the minor subjective details of syntax. Similar to worrying about what color of nail polish works best while ignoring the symptoms of a heart attack.

            1 Reply Last reply
            0
            • E Eytukan

              I'm about to write the coding standards doc for a team. I've been using Hungarian notation ever since I stated coding. The blogs that I read online rant against use of Hu system on OO languages, but I have few questions: Though it's C++ or C#, we do have primitive data types everywhere. In fact, for smaller projects, primitive data types would account for 90% of the variables. Now I'm dealing with a lot of nummbers , flags & so on. How do I know what datatype it is? For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home. I just open it in notepad and try to figure out what datatypes all these variables are. No where I can figure out this. Then why the heck everybody rants against this convention? I'm going ahead insisting on sticking with the Hu notion. If anybody has a valid reason against it, I'm all ears to it. (if you dont like Hu notation, please dont express it with the 1 vote here :sigh: )

              Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

              J Offline
              J Offline
              john morrison leon
              wrote on last edited by
              #90

              Hungarian notation is very useful as long as you don't concatenate too many prefixes and you only use it when it actually helps.

              I find the 'm_' prefix for class member and the 'p' prefix for pointer very helpful and will protest at code that doesn't use it. After using 'm_', I feel free to add another prefix as in 'm_pCursor' as this remains easy on the eye. After using the 'p' prefix I really want a capital letter so that the p stands alone and is not mistaken for anything else. For me, prefixing the data type is secondary to this as most IDEs will tell you the data type simply by hovering the mouse.
              I use 'n' when my logic requires a positive whole number and 'i' when my logic requires an iterator although its implementation may be size_t or int depending on the need to use -1 to represent it pointing nowhere.
              I use prefixes for controls btnName, edtName.
              I use established concatenations such as lpzString but try to avoid creating new ones.

              1 Reply Last reply
              0
              • F Fabio Franco

                So far, no matter what, a great potential for confusion arose between CP members, imagine in between non-hamsters.

                "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson "Our heads are round so our thoughts can change direction." ― Francis Picabia

                R Offline
                R Offline
                Randy Bartels
                wrote on last edited by
                #91

                Hungarian notation or not, just leave out the damn underscores!!!

                Randy

                1 Reply Last reply
                0
                • R Roger Wright

                  In every accounting system I've ever used, your assumption would be wrong. ;P

                  Will Rogers never met me.

                  J Offline
                  J Offline
                  JonShops
                  wrote on last edited by
                  #92

                  I'd say that symbol vs meaning is philosophically always going to make that perfect symbol an impossibility. Code should be self-documenting, but any project should also document beyond the code! My rule of thumb is to use Hu for distinguishing type details (zero-termed, length-specified, pointer or value, etc.) especially in COM, say; and for module-level designation. For me, I think it's fair to make a person look into what a variable is/means, but its symbol should let them know where to look. What bugs me are magic symbols that just appear in a tight context, like a function.

                  JonShops -- Fun really begins with the words, "So what in the World do I do now?"

                  1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    I've never liked it from the first time I saw it (it was in the standard at one place I worked -- using C) and I never use it in my own code. It's silly and you would have to change the variable name if you change the datatype. Having said that; here's the right way: http://www.joelonsoftware.com/articles/Wrong.html[^]

                    N Offline
                    N Offline
                    Nagy Vilmos
                    wrote on last edited by
                    #93

                    Having re-read the article, there is a distinction between App Hungarian and the loathed System Hungarian. In the original, the notation denoted the usage type rather than the data type. This means the data type may change, but the notation does not.


                    Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                    P 1 Reply Last reply
                    0
                    • N Nagy Vilmos

                      Having re-read the article, there is a distinction between App Hungarian and the loathed System Hungarian. In the original, the notation denoted the usage type rather than the data type. This means the data type may change, but the notation does not.


                      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #94

                      Exactly.

                      1 Reply Last reply
                      0
                      • E Eytukan

                        I'm about to write the coding standards doc for a team. I've been using Hungarian notation ever since I stated coding. The blogs that I read online rant against use of Hu system on OO languages, but I have few questions: Though it's C++ or C#, we do have primitive data types everywhere. In fact, for smaller projects, primitive data types would account for 90% of the variables. Now I'm dealing with a lot of nummbers , flags & so on. How do I know what datatype it is? For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home. I just open it in notepad and try to figure out what datatypes all these variables are. No where I can figure out this. Then why the heck everybody rants against this convention? I'm going ahead insisting on sticking with the Hu notion. If anybody has a valid reason against it, I'm all ears to it. (if you dont like Hu notation, please dont express it with the 1 vote here :sigh: )

                        Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

                        S Offline
                        S Offline
                        Stefan SeelandOld
                        wrote on last edited by
                        #95

                        VuNic wrote:

                        For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home.

                        100k of code? correct me if i am wrong: this amount of code fits on everything which was produced since the late 80s. I think that the main intention for advising not to use hungarian notation: hungarian notation is redundant information to your declaration.

                        E 1 Reply Last reply
                        0
                        • S Stefan SeelandOld

                          VuNic wrote:

                          For example, the code is a 100K line code and I cannot copy the entire project to my disk to review that at home. I choose to copy a 300 lines code block with multiple functions to review it at home.

                          100k of code? correct me if i am wrong: this amount of code fits on everything which was produced since the late 80s. I think that the main intention for advising not to use hungarian notation: hungarian notation is redundant information to your declaration.

                          E Offline
                          E Offline
                          Eytukan
                          wrote on last edited by
                          #96

                          100K lines of code is 1,00,000 lines of code right? Then I'm wrong. It should be around 1,30,000+ considering the code that we later converted as libraries. It was a medical research project. It was HUGE. Not just these, I've worked on projects that casually run over 100K lines of code. Of course I do not write them from scratch but clean the scratches here and there. And some show stopping critical fixes too. I'm still finding Hu notation to be helping, I'm sticking with it for C#. :)

                          Starting to think people post kid pics in their profiles because that was the last time they were cute - Jeremy.

                          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