• TopTension (unregistered)

    So Hungarian Notation is a WTF these days?

    There are good reason pro and contra, you can take it or leave it. But a WTF?

  • (cs) in reply to TopTension
    TopTension:
    So Hungarian Notation is a WTF these days?
    Wouldn't the Hungarians find that offensive and racist?
  • TopTension (unregistered)

    Only if you mimic Hungarion botation and don't get it right:)

  • BrainrotFromVB.Net (unregistered) in reply to TopTension
    TopTension:
    So Hungarian Notation is a WTF these days?
    Yes!
  • abigo (unregistered) in reply to TopTension
    TopTension:
    So Hungarian Notation is a WTF these days?

    There are good reason pro and contra, you can take it or leave it. But a WTF?

    It's usually a strong indicator of Cargo Cult Programming.

  • (cs) in reply to TopTension

    Yes. Hungarian Notation is, and always has been, a WTF. If you're using a strongly typed language, it means that you don't trust the compiler or aren't prepared to deal with compiler errors. If you're using a weakly typed language, it demonstrates that you're trying to enforce strong-typing-by-convention- which doesn't work. It provides a false sense of type safety ("the variable is named strFoo, it must hold a string" is a statement of hope, not reality).

    In the name of being "self-documenting", it favors knowing what prefixes mean over knowing what the code does ("Oh, gStrFoo", it's a global, so I know to be careful about touching it. I don't know what or how this variable is used, but I know it's global! Self documenting!")

    What makes Hungarian Notation TRWTF, however, is popular it was. This I will never understand. I remember when I was a little n00b programmer, and on my first job, I was taught Hungarian Notation. Even then, I demanded to know, "Why?" The answer always was, "It's the standard. Do it."

  • Whatever (unregistered)

    Call me old-fashion, but I like to know the type of my variable without hovering over it with my mouse. People act like it's the devil, it's just a preference (mostly, depending how you use it).

    Userid = ...well it' a user id, I have no idea what goes in it, but it's a userid

    guidUserID = it's a userid, and it holds a guid....

    I still prefer the latter, you say you don't? Well that's fine too, but why keep hammering on it when it's just preference...

  • (cs) in reply to ochrist
    ochrist:
    Wouldn't the Hungarians find that offensive and racist?
    Jobbik considers the Hungarians a superior race, and consequently will declare war upon the poor OP. Then the EU will step in and say: hey, you can't declare war like that! We will lower your agricultural subsidies. Then the Hungarians will say that they have been victimized by a racist, and the EU will turn against the OP and extradite him to the US, where the president's daughter has not been seen since she went to a health clinic in ... Hungary!
  • faoileag (unregistered) in reply to Remy Porter
    Remy Porter:
    Yes. It is, and always has been, a WTF.
    No, I can't agree on that one.

    In C++, pointers are occasionally used. Pointers point to memory locations, in other words: are integers. Prefixing them with a "ptr" like ptrMeaningOfLifeComputationResult makes it clear that an address in memory is meant - if you use meaningOfLifeComputationResult, you could be tempted to expect 42 instead of something like 12ab45ff.

    It also comes in handy to differentiate between variables representing the same data in different types. Consider: var strDateIn8DigitFormat = '20130418'; var intDateIn8DigitFormat = parseInt(strDateIn8DigitFormat);

    But in something like strTextForLabelFirstName = 'Firstname' the "str" prefix is clearly superfluous and should be avoided.

  • warlaan (unregistered) in reply to Remy Porter

    "What makes Hungarian Notation TRWTF, however, is popular it was. This I will never understand."

    There was a time when IDEs were not able to use colors to mark keywords and when it was not possible to display tooltips when you hovered over a variable name with the mouse. (There actually even was a time when people had to read code from printouts...)

    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.

  • Brian Bobley (unregistered) in reply to faoileag
    faoileag:
    Pointers point to memory locations, in other words: are integers.

    Integers of type char* and so on though ...

  • (cs)

    Well to be fair, at least the comment warned about the 'Complete'. It would have been more evil of the original coder to just leave the comment out and watch the fireworks when some future schmuck changed that text string....

    Now that we know that 'Complete' may have side effects, we know to be gun-shy about touching ANY text string in that monstrosity... :-)

    Yazeran

    Plan: To go to Mars one day with a hammer.

  • (cs) in reply to faoileag

    I'm tempted to flex on my "hungarian is evil" for the special case of pointers, only because pointers require a very different syntax.

    Tempted, but I won't. And the main reason that I won't, is that if the purpose and meaning of the variable isn't clear from its context, then your context is broken. Hungarian notation remains a way for unclear, difficult to read code to pretend that it's not unclear or difficult to read.

    I recognize that the real world makes it difficult to write short methods, keep variables scoped to very brief and easy to understand blocks. Hungarian notation is a great way to make 300 line functions readable. But maybe the problem is that you shouldn't be writing 300 line functions.

    The only time I ever have to check what type a property or parameter has is when I am using an API I don't know. Hungarian notation wouldn't help much, since knowing the type still doesn't help me understand the meaning. I'm gonna need the docs anyway.

    Also, your example of representing the same data with different types would make me cry if I saw that in actual code. 90% of the time, the prefix is noise- I don't need the prefix to understand the type of the variable. So I ignore it- but now you're naming variables the exact same thing, except for the prefix. Suddenly, the prefix ceases to be handy documentation, and now it's a vital indicator as to which variable I should use for which thing. That's taking Hungarian Notation and making it actively evil.

  • faoileag (unregistered) in reply to TGV
    TGV:
    Then the EU will step in and say: hey, you can't declare war like that!
    Well, the parliament in Strasbourg is dominated by the European People's Party, which is center-right and tends to be extremely soft on the Hungarian government, which is not exactly a leftwing government... no, they won't use such harsh language. They would not even send the hungarians to bed without tv.
    TGV:
    We will lower your agricultural subsidies.
    Such harsh measures are reserved for France ;-)
    TGV:
    and the EU will turn against the OP and extradite him to the US, where the president's daughter has not been seen since she went to a health clinic in ... Hungary!
    Gasp! You are not saying that the CIA operates secret health clinics in eastern europe contries? ("Confess! Or you won't get your botox shot!!")

    And does that mean that the company owner, who currently stands trial for sub-prime breast implants, is a secret undercover agent?

  • (cs) in reply to Remy Porter
    Remy Porter:
    Yes. Hungarian Notation is, and always has been, a WTF. If you're using a strongly typed language, it means that you don't trust the compiler or aren't prepared to deal with compiler errors. If you're using a weakly typed language, it demonstrates that you're trying to enforce strong-typing-by-convention- which doesn't work. It provides a false sense of type safety ("the variable is named strFoo, it must hold a string" is a statement of hope, not reality).

    In the name of being "self-documenting", it favors knowing what prefixes mean over knowing what the code does ("Oh, gStrFoo", it's a global, so I know to be careful about touching it. I don't know what or how this variable is used, but I know it's global! Self documenting!")

    What makes Hungarian Notation TRWTF, however, is popular it was. This I will never understand. I remember when I was a little n00b programmer, and on my first job, I was taught Hungarian Notation. Even then, I demanded to know, "Why?" The answer always was, "It's the standard. Do it."

    Tsk. You need to distinguish between Systems HN and Apps HN. The SHN habit of encoding the actual type of the variable in a prefix(1) to its name is indeed a WTF, albeit is relatively mild one.

    (1) Some folks like to use the prefix as the whole name. They deserve to be stabbed repeatedly.

    AHN, on the other hand, encodes useful information about what a variable is contaminated with rather than what its programming language type is. So for example, imagine a system where string variables might contain some sort of raw text, or they might contain some sort of XML-safe or HTML-encoded text, or they might contain SQL-cleansed text (whatever that means. We impose a reasonable rule that a variable contains a maximum of one sort of text, and mark it with the sort of ill the variable is contaminated with:

    std::string rawUserInput; // "raw" indicates raw text
    std::string xsafeProcessedInput; // "xsafe" indicates XML-safe text
    std::string sqlsafeDatabaseReadyInput; // "sqlsafe" indicates SQL-safe text
    We also provide conversion functions:
    xsafeProcessedInput = xsafeFromRaw( rawUserInput ); // OK
    xsafeProcessedInput = rawFromXsafe( rawUserInput ); // NOT OK
    The variable name warts align with the function name warts so that a code reviewer will be able to see that the first one is OK (passes raw-contaminated text to a "from raw" function that returns XML-safe text that is stored in an XML-safe variable) but the second is not (passes raw-contaminated text to a "from XML-safe" function that returns raw text that is stored in an XML-safe variable - a definite no-no).

    It's at best a very mild WTF, because it suggests a lack of confidence in the quality of the code. One specific advantage it gives (up to a point) is that you can use automated methods to validate the use of the correct type of contamination.

    Contextual notations such as "g" for globals, various prefixes or suffixes for member variables, and "p" for pointers are neither SHN nor AHN, and their use is debatable. I personally favour prefix "m_" as a notation for members in languages that don't require this. / self. / this-> to introduce their use. So Python doesn't get m_ prefixes because all member variables have to be accessed as self.thingy, but C++ does because you are allowed to just access m_thingy from a member function without saying this->m_thingy. I'm indifferent on the use of a "p" prefix for pointers, and generally opposed to global variables, whatever the naming convention.

  • faoileag (unregistered) in reply to warlaan
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.
    What is this IDE you are speaking about?

    vi certainly does not impart type information to the developer that easily...

  • (cs) in reply to warlaan
    warlaan:
    There was a time when IDEs were not able to use colors to mark keywords and when it was not possible to display tooltips when you hovered over a variable name with the mouse.

    Here's the thing: I never use the IDE to check the type of a variable. I generally just look at the code, because the variable declaration is someplace convenient, like a few lines above where I'm using it. Or the variable is named something that semantically implies its type. "DueDate" is how we say it in English. "dteDue" or "dteDueDate" is not.

  • ZoomST (unregistered) in reply to faoileag
    faoileag:
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.
    What is this IDE you are speaking about?

    vi certainly does not impart type information to the developer that easily...

    Obviously you are not using the new vi for Windows 8. Surely it only uses a couple of GB of memory when launched, and needs a permanent internet connection...
  • faoileag (unregistered) in reply to Remy Porter
    Remy Porter:
    but now you're naming variables the exact same thing, except for the prefix. Suddenly, the prefix ceases to be handy documentation, and now it's a vital indicator as to which variable I should use for which thing. That's taking Hungarian Notation and making it actively evil.
    Depends on how broken your language's automatic type conversion is. Consider, in Javascript: var a = '10'; var b = '02'; var c = 10; var d = 2; var abp = a + b; var cdp = c + d; var abm = a - b; var cdm = c - d;

    Sorry, but in that language a bit of Hungarian Notation can be extremely helpful because the automatic type conversion can really mess things up for you.

  • faoileag (unregistered) in reply to ZoomST
    ZoomST:
    faoileag:
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.
    What is this IDE you are speaking about?

    vi certainly does not impart type information to the developer that easily...

    Obviously you are not using the new vi for Windows 8. Surely it only uses a couple of GB of memory when launched, and needs a permanent internet connection...
    Does it have tiles? I don't want it if it doesn't have tiles!
  • (cs) in reply to faoileag
    faoileag:
    In C++, pointers are occasionally used. Pointers point to memory locations, in other words: are integers.
    Go away and study the history of C and C++ before you spout nonsense like this. On most modern platforms, a plain pointer is a single integer-like value, but there have been exceptions. Before the rise of the 80386, "x86" programmers had to put up with segmentation(1), wherein a pointer might be a single integer-like value, or it might be two rather than a single larger one.

    (1) Strictly speaking, x86 was prone to segmentation until the rise of x64, but in 32-bit systems nobody actually uses the full segmentation capability of x86 for anything more than allowing threads to access their Thread Control Blocks at a fixed location.

    Even on systems where we don't have segments, and so don't have multi-part plain pointers, C++ pointer-to-member-function variables are, in general, not single integer-like values. They are more or less compelled to be miniature structs containing some complicated information. Have a long, long think about how you would implement a pointer-to-member-function that can point effortlessly to either a virtual member function or a non-virtual one without having to have the compiler generate an endless series of trampoline function stubs in case someone wants to form the address of a member function, and to also support comparing such pointers accurately. It's non-trivial - there are solutions, but they have severe complications when you introduce amusement like conformant return values.

  • (cs) in reply to faoileag

    Nope, JavaScript is even worse when you use Hungarian notation, because you have no way to guarantee that the type in the variable is the type the Hungarian notation claims it is, and it's trivially easy to make a mistake which causes JavaScript to change the type of a piece of data into something you don't think it should be.

    Just because somebody hands you a variable called "strFoo" doesn't mean it contains a string. I once inherited code that had a variable named "intProjectNumber". The variable held things like "QR-1554-PL".

    If there are no compile-time type checks, all Hungarian notation does is add noise to your code and a false sense of security.

  • Leo (unregistered) in reply to faoileag
    faoileag:
    Remy Porter:
    but now you're naming variables the exact same thing, except for the prefix. Suddenly, the prefix ceases to be handy documentation, and now it's a vital indicator as to which variable I should use for which thing. That's taking Hungarian Notation and making it actively evil.
    Depends on how broken your language's automatic type conversion is. Consider, in Javascript: var a = '10'; var b = '02'; var c = 10; var d = 2; var abp = a + b; var cdp = c + d; var abm = a - b; var cdm = c - d;

    Sorry, but in that language a bit of Hungarian Notation can be extremely helpful because the automatic type conversion can really mess things up for you.

    And, once again, the real WTF is Javascript.

  • Noughmad (unregistered)

    Do Not Double the Killer Delete Select All Complete!

  • MatsH (unregistered) in reply to TGV
    TGV:
    Jobbik considers the Hungarians a superior race, and consequently will declare war upon the poor OP. Then the EU will step in and say: hey, you can't declare war like that! We will lower your agricultural subsidies.

    You misunderstand. You can't declare war like that - the compiler won't stand for it! You will get all kinds of errors and warnings...

  • faoileag (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    faoileag:
    In C++, pointers are occasionally used. Pointers point to memory locations, in other words: are integers.
    Go away and study the history of C and C++ before you spout nonsense like this. On most modern platforms, a plain pointer is a single integer-like value, but there have been exceptions.
    So, if you agree, why go away? I'm not talking about the exceptions here - I'm talking of everyday pointer arithmetic or debugging (sorry, no debugger wa attachable at the time) with sprintf("myPtr=%ll", myPtr);
  • (cs)

    Ah, the Hungarian Notation rants...

    What I'm going to say below is for C++. In other languages, YMMV.

    First of all, C++ has lots of lovely implicit type conversions. This goes to the point you can substitute the type of a variable with another one, and nobody notices. So if you embed type in a variable, you make it much more difficult to switch type later on.

    Secondly, templates. As soon as both conversion operators and templates get in the game, trying embed a "type" into your variables makes you pretty much screwed.

    Third, for those who say "but it helps me remember the type!". If you need to scroll more than 50 lines up or down to see the type of your variable, you're doing something wrong.

    Also, to those who complain their IDE does not have the least amount of prediction available: stop using Notepad. Pretty much any other editor or IDE has builtin support or plugins for some form of autocompletion. (That includes Vim, by the way).

    Next, if the encoding is not semantically important, don't encode it. Usually your logic isn't going to change a lot whether you have a value, a reference, a pointer, a const reference, a rvalue reference, or a smart pointer. Either that, or it's obvious from context (e.g. a copy or move constructor).

    If it's so important to know that userId is actually a GUID, why not call it userGuid?

    That being said, if multiple objects with the same type but different meanings exist in the same context, (e.g. escaped and unescaped strings), go ahead. It might be even more clear to write unescapedInput and escapedInput instead of something like usInput and esInput, though.

  • Okay (unregistered) in reply to warlaan
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.

    typedef Int bool; typedef Double int; typedef Bool double;

    Int ptrString = true;

    Where's your IDE tooltip now?

  • faoileag (unregistered) in reply to Remy Porter
    Remy Porter:
    I once inherited code that had a variable named "intProjectNumber". The variable held things like "QR-1554-PL".
    I agree with you that it can be misleading. Unfortunately, just as much as any varaible name can be misleading. So "intProjectNumber" is misleading if the value is "QR-1554-PL"? But so is projectNumber, when in reality what you have is a projectCode.

    And to get back to the somewhat contrived example from earlier on - is: var todaysDate = '20130418'; var dateToday = parseInt(todaysDate, 10); so much better?

    var foo1 = todaysDate + todaysDate; var foo2 = dateToday + dateToday; still gives you different results for foo1 and foo2 but now I have to deduct from the context which variable has which type everytime I need to use one of them.

    Can't really see how that makes my life easier in larger projects.

  • (cs) in reply to Okay
    Okay:
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.

    typedef Int bool; typedef Double int; typedef Bool double;

    Int ptrString = true;

    Where's your IDE tooltip now?

    First of all, that's invalid code. Surely you meant:

    typedef bool Int; 
    typedef int Double; 
    typedef double Bool; 
    
    Int ptrString = true;
    

    Secondly,

    places cursor on Int presses Ctrl+] (go to declaration) Oh, some wiseass decided to typedef bool as Int. presses Ctrl+T (go back)

  • bluesman (unregistered)

    I prefer camelToe notation.

  • faoileag (unregistered) in reply to SeySayux
    SeySayux:
    Third, for those who say "but it helps me remember the type!". If you need to scroll more than 50 lines up or down to see the type of your variable, you're doing something wrong.
    Ever heard of the notion "member variables"? These nifty things are usually declared in the .h files in C++ projects, so you not only have to scroll 50 lines to see their type declaration, you have to open another file prior to it as well.
  • warlaan (unregistered) in reply to Okay

    Hm, that is a very good example. In that case hungarian notation would help, but to be honest: any kind of violence against that idiot who wrote that would be an even better solution.

  • warlaan (unregistered) in reply to Okay
    Okay:
    warlaan:
    But I agree that nowadays it is a WTF, because it only adds information that is supplied by the IDE and that can be faulty onace a data type is changed.

    typedef Int bool; typedef Double int; typedef Bool double;

    Int ptrString = true;

    Where's your IDE tooltip now?

    Hm, that is a very good example. In that case hungarian notation would help, but to be honest: any kind of violence against that idiot who wrote that would be an even better solution.

  • (cs) in reply to faoileag
    faoileag:
    SeySayux:
    Third, for those who say "but it helps me remember the type!". If you need to scroll more than 50 lines up or down to see the type of your variable, you're doing something wrong.
    Ever heard of the notion "member variables"? These nifty things are usually declared in the .h files in C++ projects, so you not only have to scroll 50 lines to see their type declaration, you have to open another file prior to it as well.

    I don't know what editor or OS you use, but mine have these nifty features called "split windows", "multiple windows", "toggle header/source" and "go to declaration". Quite handy!

  • (cs) in reply to faoileag

    It may be a "project code" to you, but to the business users, it's a "project number". Variable names should always map to the domain as easily as possible.

    Were I building your contrived example, it would look more like this:

    var todayInput = '20130418'; //this isn't a date, it's a string. 
    var dateAsNumberDONOTUSE = parseInt(todayInput, 10); //HACK why the hell would I ever do this? It's bad enough to have a date as a string, but as an integer?
    var unixDate = toUnixTime(todayInput ); //the only way to store a date as an integer. Note, I don't need to call it "intUnixDate", since the name implies that it must be a date.
    var targetDate = parseTheDateString(todayInput); //actually create a date object. By naming it according to what I plan to do with it, it should be clear that it actually represents a REAL date object.
    

    Now, I know the role of every value in the application. Knowing what it is for is far more valuable than knowing what it's type is. I really don't care about its type- I mean, if I did, I wouldn't be using JavaScript, would I? I need to know what the value is for. If I know that, I also know what it's type should be.

  • (cs) in reply to faoileag
    faoileag:
    you have to open another file prior to it as well.

    I dunno, I constantly refer back to the class definition, so I always have that file open (except when using IDEs that can autocomplete). How would Hungarian notation help me recall the exact naming of every member? If I've already used the member in a method, then I obviously knew what the type was when I used it- I can easily tell at a glance what the type is (if I've accessed it, I've either gotten its value or set its value- and I should know the type of the get/set target).

    It seems like your main argument for using Hungarian notation is that it allows you to write code which will probably compile and may do what you want, without ever actually reading any of the code around it.

  • (cs) in reply to faoileag
    faoileag:
    Steve The Cynic:
    faoileag:
    In C++, pointers are occasionally used. Pointers point to memory locations, in other words: are integers.
    Go away and study the history of C and C++ before you spout nonsense like this. On most modern platforms, a plain pointer is a single integer-like value, but there have been exceptions.
    So, if you agree, why go away? I'm not talking about the exceptions here - I'm talking of everyday pointer arithmetic or debugging (sorry, no debugger wa attachable at the time) with sprintf("myPtr=%ll", myPtr);
    No, I don't agree. You said that pointers are integers, i.e. 100% of the time a pointer is an integer. I said that on most modern platforms, one type of pointer is an integer-like value, and then went on to show some of the ways in which pointers might be other stuff than a single integer-like value.

    Do you really think you can print a pointer using %ll? Go away, you are living in a state of sin. On a typical 32-bit platform, it will hoover up 32 bits of assorted garbage along with the bits of the pointer. You probably meant %p, which is the standards-conformant way of formatting a pointer, and which takes care of all the varied oddities of your platform.

    If you try to printf anything using format specifiers that don't match the types passed in, you are in for a surprise. On 16-bit platforms, int and long aren't the same size, so trying to match %d versus a long variable will go wrong. Some platforms have pointers that don't match the size of int, so printing an pointer with %d or %X will go wrong. And the behaviour of a program with this kind of mismatch is undefined, so running it on a DeathStation 9000 will cause millions of unwitting citizens to die in nuclear explosions. (All joking aside, if the idea of your code having undefined behaviour doesn't scare you ****less, there's something wrong with you.)

    Clear?

  • (cs) in reply to TopTension
    TopTension:
    So Hungarian Notation is a WTF these days?

    There are good reason pro and contra, you can take it or leave it. But a WTF?

    Yes it's a WTF. There's no real reason to use it. If you need to indicate that a particular variable is a string, you probably need a better name for it in the first place.

    strCustomerName is redundant. CustomerName should indicate that it's a string by virtue of being a name.

    About the only place I don't mind seeing Hungarian Notation is in the UI, since txtFirstName seems better than FirstNameTextBox.

  • XXX (unregistered)

    All the XXX in here is making me want to start pron mode and surf me some pron ...

  • Todd Lewis (unregistered) in reply to bluesman
    bluesman:
    I prefer camelToe notation.

    i'M tRYING tO lEARN tO lOVE cAPSlOCK nOTATION.

  • warlaan (unregistered)

    I would love to use hungarian notation, but brainfuck does not have variable names.

  • Bring Back TopCod3r (unregistered) in reply to Remy Porter
    Remy Porter:
    Yes. Hungarian Notation is, and always has been, a WTF.

    Yes, it always was, although at one time I dare not speak out. I feel the same way about XML today (although I think the tide is finally changing).

    Remy Porter:
    What makes Hungarian Notation TRWTF, however, is popular it was. "

    Microsoft heavily promoted it, in all documentation, sample codes etc. If you were working for a Microsoft shop, you would almost certainly be using it.

  • faoileag (unregistered) in reply to Remy Porter
    Remy Porter:
    faoileag:
    you have to open another file prior to it as well.
    I dunno, I constantly refer back to the class definition, so I always have that file open
    So do I - usually at least. I was just trying to make a point about "if you have to scroll 50 lines to see the type declaration".
    Remy Porter:
    It seems like your main argument for using Hungarian notation is
    Don't get me wrong - I'm not advocating it and I hardly ever use it myself. I was just taking a bit of a stance against the complete condemnation of HN you posted a bit earlier.
    Remy Porter:
    that it allows you to write code which will probably compile and may do what you want, without ever actually reading any of the code around it.
    Let me put it like this: it sometimes makes it easier to see what's going on if all you want to spare is a few glances.

    Yes, the type information HN carries can be wrong, but people who do not clean up their code after changes that invalidate the type information inherent in a variable that adheres to HN will usually produce hard-to-maintain code even in an HN-free environment. Ternary bools like true/false/file_not_found in C++ or Javascript? Some people will be so lazy or so pressed by deadlines that they simply don't care.

    And as an aside: postings about today's article seem rather rare so far... Hungarian Notation seems to hit a nerve or two :-)

  • faoileag (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    You said that pointers are integers, i.e. 100% of the time a pointer is an integer. I said that on most modern platforms, one type of pointer is an integer-like value, and then went on to show some of the ways in which pointers might be other stuff than a single integer-like value.
    Ah, ok, I think I see where the problem is... you see, I meant "integer-like value" when I wrote integer.

    In other words: for me, "integer" in that context meant "a number from N" and not the data type "int".

  • Hasse (unregistered)

    All the rants on hungarian notation .... I thought GOTO's where considered harmful

  • Geoff (unregistered) in reply to Remy Porter
    Remy Porter:
    Nope, JavaScript is even worse when you use Hungarian notation, because you have no way to guarantee that the type in the variable is the type the Hungarian notation claims it is, and it's trivially easy to make a mistake which causes JavaScript to change the type of a piece of data into something you don't think it should be.

    Just because somebody hands you a variable called "strFoo" doesn't mean it contains a string. I once inherited code that had a variable named "intProjectNumber". The variable held things like "QR-1554-PL".

    If there are no compile-time type checks, all Hungarian notation does is add noise to your code and a false sense of security.

    I was going to say something along these lines. Hungarian notation should ONLY be used in strong type languages. I think in most cases it is an unnecessary verbosity but I don't consider them a WTF. If you like the style I am totally okay working with your code and using it. I also recognize there certainly are cases where it makes reading and understanding faster; and also cases where it might reduce errors by calling attention to implicit type casts that are allowed but might have undesired consequences. It might lead you to questions like "I am dividing an integer by a float, do I also need to use something like floor or ceiling to get an appropriate value for what I am trying to implement?"

    If you use it though make darn sure its correct. If you name something intFoo I expect foo to be an integer; not a double, float, char, unsigned, long, or string representation.

  • Darth Paul (unregistered) in reply to Remy Porter
    Remy Porter:
    Yes. Hungarian Notation is, and always has been, a WTF.

    It was useful back when IDEs did not have tooltips.

    Also, a primary purpose of such notation was to expand the possible range of variable names without having to worry about issues such as reserved words, etc. I am surprised that so many people never realised this.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered) in reply to faoileag
    faoileag:
    Ever heard of the notion "member variables"? These nifty things are usually declared in the .h files in C++ projects, so you not only have to scroll 50 lines to see their type declaration, you have to open another file prior to it as well.
    There's a difference between warts that indicate a variable's type (int, boolean, string, pointer, etc.) and warts that indicate a variable's scope (global, class member, etc.) or usage ("pFoo" can be useful without using variable type warts).

    Just because one type of wart might be useful in some circumstances doesn't validate the use of other types of warts or HN in general.

  • Black Bart (unregistered) in reply to XXX
    XXX:
    All the XXX in here is making me want to start pron mode and surf me some pron ...

    There's a lot of 'gstr'ings also being shown.

Leave a comment on “Do Not Remove Complete!”

Log In or post as a guest

Replying to comment #:

« Return to Article