Thread: hungarian notation

  1. #31
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    either way, I would like C++0x to come with some refactored code, sick of seeing scALs::SP_XXX etc.

  2. #32
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by indigo0086
    I would like C++0x to come with some refactored code, sick of seeing scALs::SP_XXX etc
    What do you mean?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #33
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I tend to prefer knowing whether a variable is a class, structure, pointer, string, float or a banana. So sz, lp, dw, w, b, byte, f etc are very helpful.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #34
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by maxorator View Post
    I tend to prefer knowing whether a variable is a class, structure, pointer, string, float or a banana. So sz, lp, dw, w, b, byte, f etc are very helpful.
    lp is kind of useless, since every pointer these days is a long pointer, so just p should suffice.
    As for the others, they depend on the actual data type, which might change (char* to std::string for example) and then you'd have to rename all the szVar names to strVar...
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  5. #35
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by cpjust View Post
    lp is kind of useless, since every pointer these days is a long pointer, so just p should suffice.
    As for the others, they depend on the actual data type, which might change (char* to std::string for example) and then you'd have to rename all the szVar names to strVar...
    Err... I don't see why anyone would do that. And besides, changing the way the string is handled everywhere is much more annoying than changing the name. Not a good example I guess.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #36
    The larch
    Join Date
    May 2006
    Posts
    3,573
    What about changing a signed integer to unsigned or the other way round?

    What about polymorphism? How do you indicate what type the pointer points to?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #37
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by maxorator
    I tend to prefer knowing whether a variable is a class, structure, pointer, string, float or a banana. So sz, lp, dw, w, b, byte, f etc are very helpful.
    Non sequitur. As has been mentioned in this thread several times, you can know the type of the variable without encoding it into the name, especially if you declare the variable near first use, and write functions that do one thing and do it well. Granted, the difference between a class and a struct will not be evident, but it is unnecessary information anyway since the language level difference is superficial, while the semantic difference (e.g., the convention of structs being used to define aggregates) can be conveyed by a descriptive name.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #38
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I agree with laserlight. I've been reading a book on Clean Code by bob martin and it highlights some of that. I've never had the need for encoded variable names when the names are descriptive and are near it's use. Anything else screams global variable and we know how that is. Even when I'm doing javascript stuff I try to keep these methodologies, and they only have var and function to work with.

    And what I meant laserlight is the variable names, type names, and defines in the standard C/C++ library that I think pollute most of their intent. It also doesn't fare well with code intelligence helpers.
    Last edited by indigo0086; 05-12-2009 at 02:19 PM.

  9. #39
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by laserlight View Post
    As has been mentioned in this thread several times, you can know the type of the variable without encoding it into the name, especially if you declare the variable near first use, and write functions that do one thing and do it well.
    You people always fight against that statement ("I just know what this variable is, it doesn't need to be descriptive.") because it's the excuse for writing bad code. I don't see that anything is different here.
    Quote Originally Posted by anon View Post
    What about polymorphism? How do you indicate what type the pointer points to?
    If the pointer can point to different types then it is a pointer to void, so you just indicate it with a p.
    Last edited by maxorator; 05-13-2009 at 06:32 AM.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  10. #40
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by maxorator View Post
    If the pointer can point to different types then it is a pointer to void, so you just indicate it with a p.
    What about any user defined type? Car? Printer? Model? BankAccount?

    HN is an unfortunate holdover from Win32 programming. If it dies yesterday it won't be soon enough. It's as worthless as most comments in code.

  11. #41
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by medievalelks View Post
    What about any user defined type? Car? Printer? Model? BankAccount?

    HN is an unfortunate holdover from Win32 programming. If it dies yesterday it won't be soon enough. It's as worthless as most comments in code.
    I agree it's useless and confusing to try to abbreviate user defined types, so they should just be a part of the real variable name (actually they are usually just subtypes anyway, because the real type is either class or structure).
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  12. #42
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by maxorator
    You people always fight against that statement ("I just know what this variable is, it doesn't need to be descriptive.") because it's the excuse for writing bad code. I don't see that anything is different here.
    There is an important difference here: a type encoding (i.e., Systems Hungarian) is not as descriptive as the type itself, and is not guaranteed to be in sync with the type. If you were arguing for a semantic encoding (i.e., Apps Hungarian), then indeed there would not be anything different from a normal descriptive name other than the need for a programmer new to the code base to learn the commonly used abbreviations.

    Quote Originally Posted by maxorator
    (actually they are usually just subtypes anyway, because the real type is either class or structure)
    It sounds like you consider class and structures to be some kind of supertypes by themselves. They are not. They are language constructs used to define types.

    EDIT:
    Quote Originally Posted by maxorator
    I agree it's useless and confusing to try to abbreviate user defined types, so they should just be a part of the real variable name
    But you stated that you "prefer knowing whether a variable is (...) a banana". How would you know if the variable was of the banana type if you do not abbreviate user defined types? Why should the built-in types and string types be treated as special cases, if (Systems) Hungarian notation is really so useful?
    Last edited by laserlight; 05-13-2009 at 10:23 AM.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #43
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by laserlight View Post
    But you stated that you "prefer knowing whether a variable is (...) a banana". How would you know if the variable was of the banana type if you do not abbreviate user defined types?
    By having the banana somewhere in the variable's name, but not as an abbreviated prefix.
    Quote Originally Posted by laserlight View Post
    Why should the built-in types and string types be treated as special cases, if (Systems) Hungarian notation is really so useful?
    Because the built-in types are the building blocks of everything else? There is a big difference between one data block (built-in types) and a collection of data blocks (structures, classes), therefore they should also be treated differently.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  14. #44
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by maxorator
    Because the built-in types are the building blocks of everything else? There is a big difference between one data block (built-in types) and a collection of data blocks (structures, classes), therefore they should also be treated differently.
    The problem is that the difference does not warrant that they should be treated differently where type encoding is concerned. You could argue that perhaps, if it made sense to use type encoding in the first place, such abbreviation would be of most utility for types that are used most frequently. This would then imply that it makes sense to abbreviate the names of the built-in types, but it would also make sense to abbreviate the names of user defined types that are used frequently.

    However, the point remains: it does not make sense to use type encoding in the first place when the type system already exists such that convention is superfluous. With respect to C++, Stroustrup even goes as far as to regard (Systems) Hungarian notation as "completely unsuitable for a language that supports generic programming and object-oriented programming".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #45
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by laserlight View Post
    However, the point remains: it does not make sense to use type encoding in the first place when the type system already exists such that convention is superfluous. With respect to C++, Stroustrup even goes as far as to regard (Systems) Hungarian notation as "completely unsuitable for a language that supports generic programming and object-oriented programming".
    How come is it superfluous? If I read code written using Systems Hungarian notation, I see the data types of variables in the code. However, sometimes when I've tried to read some code written in "this_is_a_variable" style, I have to search the files for the declaration so I could know what type it is. Then when I see a next variable I do the same thing all over again. Imagine you have a variable "movie_rating" and you see the code for the first time. How do you know whether it is a byte, word, doubleword, float, double or a pointer to some structure or class containing more specific information?
    "The Internet treats censorship as damage and routes around it." - John Gilmore

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CamelCase VS Hungarian notation, which is better?
    By meili100 in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2007, 09:31 PM
  2. Hungarian Notation
    By FOOTOO in forum C Programming
    Replies: 6
    Last Post: 05-20-2005, 08:35 PM
  3. Hungarian Notation POLL
    By maxhavoc in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 06-21-2004, 10:52 AM
  4. hungarian notation
    By confuted in forum C++ Programming
    Replies: 2
    Last Post: 07-28-2003, 01:19 PM
  5. Hungarian Notation
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 10-13-2001, 11:17 AM