Hungarian notation gone wrong



  • The application I'm working on occasionally uses Hungarian notation in naming variables. For example, the current user mode is stored in a long integer, giving the following variable declaration:



    long lusermode;



  • @Carnildo said:



    long lusermode;

    That has to be a joke by the original programmer. It just has to be. In order to not lose faith in humanity, I must believe that they deliberately used this variable naming convention throughout the project, just so they would occasionally have things like this. 



  • @Licky Lindsay said:

    @Carnildo said:



    long lusermode;

    That has to be a joke by the original programmer. It just has to be. In order to not lose faith in humanity, I must believe that they deliberately used this variable naming convention throughout the project, just so they would occasionally have things like this. 

    I certainly would have. 



  • I write a lot of hack VBA code in access (go ahead and say it: that's the real WTF) anyway ...

    One data mangler is a sub called CopyOutH but typed it lower case to run it earlier and noticed:
    copyouth

    Ok, boo! not funny. It is funny when you find your sub make up other words or phrases you didn't think about.

    Long ago when spellcheck was still in its infancy I had a VP last name Pentis ... you can fill in the blanks there.

     


     



  • Perl code is full of this sort of thing, usually centred around the die() function....

    open(INFILE, "<", $file_name) or die();

    or

    if (!defined($needed_command_line_argument)) show_usage() and die();

    etc.

    There was also a module that I had seen somewhere along the line that had an enhanced version of the die() function, called die_trying().


     



  • @Critter said:

    There was also a module that I had seen somewhere along the line that had an enhanced version of the die() function, called die_trying().

    Did you ever call the statement

    get_rich() or die_trying();

     



  • @Carnildo said:

    The application I'm working on occasionally uses Hungarian notation in naming variables. For example, the current user mode is stored in a long integer, giving the following variable declaration:



    long lusermode;

     

    This notation makes sense in PL/SQL where a good editor with occurrence highlighting and declaration info is rare to come by.

    But in java? No... BUT i've seen worse...

    Try these code snippets form a REAL PRODUCTION application from my prev company:

    User obj_user

    ActionForm obj_object --> this goes with the next one in the same function

    AccessManager obj_object2

    String str_string

    String str_object

    String str_username

     

    Also Camel Caps seem to not have migrated from java standards to this app...

    String obj_sql_repository_manager_object

     

    YAY!

    Now in pl/sql this was helpful... for about 20 minutes, then because they used

    li_object I had to look it up anyways... also something like

    li_user  varchar(250);  was common... opse a varchar is not an int... wah-wah (this made the hungarian notation garbage because it was never accurate :P)



  • Using Hungarian notation is a WTF itself.

    Man, I cannot tell you how I hate that.
    I'm a C++ programmer, I was looking for a job in the past three months. Now I have found my place, but here's a story.
    There was one company, everything went fine with my first interview. At our second meeting I was talking with my forthcoming team leader. Everything was fine, it seemed like I was going to get the job. After an hour talking, it turned out, that at this company everybody was using the Hungarian notation, and I should too. It was a coding policy at the company, they told me. This team leader was very suprised when I said thank you, and sorry I had to go. He asked why, and my answer was, that the company, where Hungarian notation is taken seriously, is a place for much worse problems.

    After that I added to my CV that I was not going to use Hn.

    I have seen too many stupidly named variables like bCheck, bIsOk, iValue, iValue2, etc. One may say that's not the problem of the naming convention but the coder's laziness, who couldn't do better even if he was'nt forced to use Hn, and his names were just as meaningless - but it's not what I see.

    /rant



  • @tray said:

    Using Hungarian notation is a WTF itself.
    Man, I cannot tell you how I hate that

    See sig. The only time I would justify using hungarian notation is in a project done in a duck-typed language when a variable must be a specific type or format and is already verified to be so.



  • I've just started using MediaWiki, and it has the most annoying naming scheme I've ever seen.  It's kind of mutant Hungarian notation I guess, all global varables start with wg, all functions start with wf, etc.



  • @Cap'n Steve said:

    I've just started using MediaWiki, and it has the most annoying naming scheme I've ever seen.  It's kind of mutant Hungarian notation I guess, all global varables start with wg, all functions start with wf, etc.


    Functions should start with wtf. At least global ones.



  • @Carnildo said:

    The application I'm working on occasionally uses Hungarian notation in naming variables. For example, the current user mode is stored in a long integer, giving the following variable declaration:

    long lusermode;

     

    That must be intentional. There wouldn't be so many separate modes that it wouldn't fit in a regular int, or maybe even a char.

     

     



  • @marinus said:

    @Carnildo said:
    The application I'm working on occasionally uses Hungarian notation in naming variables. For example, the current user mode is stored in a long integer, giving the following variable declaration:

    long lusermode;

    That must be intentional. There wouldn't be so many separate modes that it wouldn't fit in a regular int, or maybe even a char.

    It's not entirely inconceivable that it may be a bit-mask with potentially more than 32 flags.  I'm more inclined to think it was deliberate however - it's not as if there isn't a precedent for jokes in code: http://www.gnu.msn.by/fun/jokes/declarations.html



  • Isn't it usually wrong?

    I have some C# code that was outsourced that uses the "sz" prefix to denote string variables.  On top of "sz" being a real Hungarian letter, it stands for "string, zero-terminated."  The problem is, of course, strings in C# are not zero terminated and the prefix is literally just noise in the code.



  • @djork said:

    Isn't it usually wrong?

    Yup. The prefix should denote something to do with the object the variable is representing, not the internal format the variable is represented with (currently. The prefixes used like this become invalid as soon as, e.g., you move it from an int to a long in C, resulting in either the variable name not changing, or ages spent on search/replace. Both WTFs in themselves)

    I have some C# code that was outsourced that uses the "sz" prefix to denote string variables.  On top of "sz" being a real Hungarian letter, it stands for "string, zero-terminated."  The problem is, of course, strings in C# are not zero terminated and the prefix is literally just noise in the code.

    Case in point.

    The sort of, IMHO, correct usage I saw was in php with string prefixes of (something akin to) es_ for escaped, ue_ for unescaped (usually referring to POST and GET variables;) with the intention that you should use es_ for SQL queries, ue_ for display etc.

     


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.