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.

    M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #17

    Using meaningful variable names reduce the need to artificially decorate variable name. And in 2012, intellisense type technology makes it easier to keep tab of what type are the variables you are using. IMO, using notepad to do code-review is counter-productive.

    Watched code never compiles.

    E 1 Reply Last reply
    0
    • M Maximilien

      Using meaningful variable names reduce the need to artificially decorate variable name. And in 2012, intellisense type technology makes it easier to keep tab of what type are the variables you are using. IMO, using notepad to do code-review is counter-productive.

      Watched code never compiles.

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

      Actually I intentionally put that as Notepad though I would be using an IDE for the code review. Because to me both IDE and notepad would mean the same unless I copy the entire project for the review.

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

      T 1 Reply Last reply
      0
      • N Nagy Vilmos

        I read 'nation' to start with and I was ready with :mad:, but I'll forgive you. This once. Hungarian notation works, as you say, well and you always know what the data type is. If you don't use it then you need to go back to the point in the code at which the variable was defined. This was indeed a problem using old fashioned non-contextual editors. With the use of modern IDE's, you can easily see the data type because of IntelliSense. I personally do not use Hungarian notation anymor, but I understand and appreciate its usefulness.


        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

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

        Nagy Vilmos wrote:

        I personally do not use Hungarian notation anymor

        Nagy Vilmos? ;)

        Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman

        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
          Steve Maier
          wrote on last edited by
          #20

          For me, I used to use Hungarian when I was coding in MFC and C++. Now that I have been using .NET I don't use it for a few reasons. The modern IDE can show you the type very easily. People have changed types and then were lazy to rename the variables. Names like these are like specs, they get out of date pretty quickly. Some people on my team use the old m_ or just m to say member variable. One person just uses an _ but at the end of the name, not the beginning. So typically since it is a religious war when it comes to things like this or where he proper place to put the curly braces, we typically just state to follow the coding convention that the person wrote the code in. If you cannot understand it, then I really don't want you on my team anyways. ;) Of course taking home 300 lines of code from your work is actually concidered IP theft where I work unless you have a company laptop and can VPN in. That and then picking notepad to view the code is just not right. At least get Notepad+.

          Steve Maier

          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.

            T Offline
            T Offline
            TheGreatAndPowerfulOz
            wrote on last edited by
            #21

            Because most people do it incorrectly. The guy, Simonyi, who invented Hungarian notation meant for the names of variables to carry the kind of thing it is, not its type. So, instead of

            int iRowScr, iColScr.
            List ilBal;

            you'd have

            int rwScreen, colScreen;
            List Balances;

            He never intended for the variable name to carry the underlying type, but rather the name should be informative of what it is.

            If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
            You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

            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
              Nelek
              wrote on last edited by
              #22

              Same answer as NagyV

              Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpfull answers is nice, but saying thanks can be even nicer.

              1 Reply Last reply
              0
              • N Nish Nishant

                DavidCrow wrote:

                What type is it: numeric (long, int, double) or alphanumeric?

                If I see accountNumber, I'd automatically assume an Int32 (.NET).

                Regards, Nish


                My technology blog: voidnish.wordpress.com

                D Offline
                D Offline
                Dr Walt Fair PE
                wrote on last edited by
                #23

                And I'd automatically assume it might have hyphens and/or spaces and should be alphanumeric. Hence I agree with the OP's idea. Personally I think all edicts are counter productive. I tend to use Hu notation for a few things in C# mainly because I know my conventions and it makes things easier to remember and find.

                CQ de W5ALT

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

                N 1 Reply Last reply
                0
                • D Dr Walt Fair PE

                  And I'd automatically assume it might have hyphens and/or spaces and should be alphanumeric. Hence I agree with the OP's idea. Personally I think all edicts are counter productive. I tend to use Hu notation for a few things in C# mainly because I know my conventions and it makes things easier to remember and find.

                  CQ de W5ALT

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

                  N Offline
                  N Offline
                  Nish Nishant
                  wrote on last edited by
                  #24

                  Walt Fair, Jr. wrote:

                  And I'd automatically assume it might have hyphens and/or spaces and should be alphanumeric.

                  It depends on the quality of your fellow devs. Most devs I work with would not have "number" in an identifier if it represents a string.

                  Regards, Nish


                  My technology blog: voidnish.wordpress.com

                  D 1 Reply Last reply
                  0
                  • N Nish Nishant

                    DavidCrow wrote:

                    What type is it: numeric (long, int, double) or alphanumeric?

                    If I see accountNumber, I'd automatically assume an Int32 (.NET).

                    Regards, Nish


                    My technology blog: voidnish.wordpress.com

                    R Offline
                    R Offline
                    Roger Wright
                    wrote on last edited by
                    #25

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

                    Will Rogers never met me.

                    N J 2 Replies 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.

                      N Offline
                      N Offline
                      Nish Nishant
                      wrote on last edited by
                      #26

                      Roger Wright wrote:

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

                      Then perhaps, I'd rename that to accountIdentifier or accountId.

                      Regards, Nish


                      My technology blog: voidnish.wordpress.com

                      F 1 Reply Last reply
                      0
                      • N Nish Nishant

                        Walt Fair, Jr. wrote:

                        And I'd automatically assume it might have hyphens and/or spaces and should be alphanumeric.

                        It depends on the quality of your fellow devs. Most devs I work with would not have "number" in an identifier if it represents a string.

                        Regards, Nish


                        My technology blog: voidnish.wordpress.com

                        D Offline
                        D Offline
                        Dr Walt Fair PE
                        wrote on last edited by
                        #27

                        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

                        N J 2 Replies 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

                          N Offline
                          N Offline
                          Nish Nishant
                          wrote on last edited by
                          #28

                          Walt Fair, Jr. wrote:

                          When someone calls and I ask for their Account Number, there's never any confusion.

                          In that case, since everyone knows it's a string, why would you want to prefix it with s or str or lpsz?

                          Regards, Nish


                          My technology blog: voidnish.wordpress.com

                          D 1 Reply Last reply
                          0
                          • N Nish Nishant

                            Walt Fair, Jr. wrote:

                            When someone calls and I ask for their Account Number, there's never any confusion.

                            In that case, since everyone knows it's a string, why would you want to prefix it with s or str or lpsz?

                            Regards, Nish


                            My technology blog: voidnish.wordpress.com

                            D Offline
                            D Offline
                            Dr Walt Fair PE
                            wrote on last edited by
                            #29

                            Because you and the devs you work with didn't know and might need to review the code? :laugh: ;P

                            CQ de W5ALT

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

                            N 1 Reply Last reply
                            0
                            • D Dr Walt Fair PE

                              Because you and the devs you work with didn't know and might need to review the code? :laugh: ;P

                              CQ de W5ALT

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

                              N Offline
                              N Offline
                              Nish Nishant
                              wrote on last edited by
                              #30

                              Walt Fair, Jr. wrote:

                              Because you and the devs you work with didn't know and might need to review the code? :laugh:;-P

                              You forget that you are talking to a super programmer here. ;P

                              Regards, Nish


                              My technology blog: voidnish.wordpress.com

                              D 1 Reply Last reply
                              0
                              • N Nish Nishant

                                Walt Fair, Jr. wrote:

                                Because you and the devs you work with didn't know and might need to review the code? :laugh:;-P

                                You forget that you are talking to a super programmer here. ;P

                                Regards, Nish


                                My technology blog: voidnish.wordpress.com

                                D Offline
                                D Offline
                                Dr Walt Fair PE
                                wrote on last edited by
                                #31

                                :cool:

                                CQ de W5ALT

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

                                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
                                  Joe Woodbury
                                  wrote on last edited by
                                  #32

                                  As pointed out above, hungarian notation was meant to signify the purpose of a type, not it's underlying type. The only notation I use is "p" for pointer, "m" for member data and "h" for handle since they indicate a fundamental difference in how they are used. My biggest problem with Hungarian notation are: 1) The abbreviations frequently makes no sense. 2) If code is ported or variables changed, the notation is often wrong. In the current code I'm working on, it's common to find sz in front of pointers, dw in front of long longs. is "b" a bool, BOOL or int? I just looked at some code with an 'h' prefix, but the original programmer had turned it into a pointer (he argues that it's a pseudo-handle--great, then encapsulate it.) 3) In connection with the above, if a data type becomes an abstract type or is extended, it can cause serious confusion. (I've see way too much code where something like bCanReplace actually holds an enumerated value. (Last year, I ported a bunch of code to Unicode in preparation for a CE port. I removed what Hungarian that I could, but the code is littered with "sz" prefixes, among other things--is the sz an ANSI or Unicode string?) 4) It is often accompanied with short variable names. Once you make variable names longer, the meaning becomes clear and the Hungarian notation becomes redundant (and, going with the above, often misleading.) Any developer that insists on using Hungarian should be forced to write a style guide on their personal notation. (On par with my hatred of Hungarian is excessive typedef'ing. Some it nice, even necessary, but I've seen code where they redefine EVERY type for no reason.)

                                  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.

                                    P Offline
                                    P Offline
                                    Philippe Mori
                                    wrote on last edited by
                                    #33
                                    1. Hungarian notation does not work well with generics or templates or code refactoring (changing an int for a long for example). 2) With modern editors, you will know the type simply by a mouse over a variable. 3) With properly written code (small functions, single responsibility classes...), it should be easy to understand the code anyway. 4) You should avoid cast and the compiler will show most incompatibilities anyway. And if you use int consistently when it make sense, type information won't be that much useful. 5) After having stop to use that notation for more than 5 years, I can say it is much better that way. By using sensible variable and function names, it is generally relatively easy to figure out what the code does. 6) If you are using primitive data types 90% of the time, then you are probably reinventing the wheel and you classes probably have way too much responsibilities. Either with BCL in .NET or STL (or boost) in C++, you should be able to use a lot of existing stuff. 7) If you want to review code, then you should also print the header.

                                    Philippe Mori

                                    1 Reply Last reply
                                    0
                                    • T Tim Groven

                                      I worked on a project where one of the data types changed. Then you have to go through the code and change the notation everywhere that variable is used. Pretty easy with search and replace, but doesn't need to be done if you just use proper naming.

                                      R Offline
                                      R Offline
                                      Rob Grainger
                                      wrote on last edited by
                                      #34

                                      That also has a pretty negative impact on source code control, resulting in changes across multiple files that would otherwise be unnecessary.

                                      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.

                                        R Offline
                                        R Offline
                                        Rob Grainger
                                        wrote on last edited by
                                        #35

                                        1. It's pug-ugly. 2. It encodes the data type directly in the variable name, if the variable's type changes, all references must be updated. 3. If you have a 300 line code block with no variable declarations, I suspect you have worse problems than use of Hungarian notation. 4. Most people who claim to use HN actually use the HN exemplified by MS in the 1990's. This is mis-use. Original usage used, for example, "i" for index, not for "integer". The prefix was meant to give the usage, not the data type. 5. Insistence of HN in your coding conventions is likely to scare off talented developers. Nowadays, with long variable names, I (along with most other developers) prefer to give variables descriptive, readable names rather than obscure names relying on "conventions" which change with the code-base.

                                        L 1 Reply Last reply
                                        0
                                        • E Eytukan

                                          I'm finding it difficult to review the code in notepad. The purpose of the review is to shoot down all the unreasonable use of static variables. But unless I copy the entire project and get the roots of all these variables, I wont be able to step into the code review. it's bad.

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

                                          R Offline
                                          R Offline
                                          Rob Grainger
                                          wrote on last edited by
                                          #36

                                          If your variable declaration's are over 300 lines away from their usage, you've probably got much worse problems than naming conventions.

                                          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