hungarian notation

This is a discussion on hungarian notation within the General Discussions forums, part of the Community Boards category; Originally Posted by maxorator How come is it superfluous? Because the type is already available due to the type system. ...

  1. #46
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by maxorator
    How come is it superfluous?
    Because the type is already available due to the type system.

    Quote Originally Posted by maxorator
    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 some structure or class containing more specific information?
    I check the declaration, which would be nearby, or in the corresponding header if it is a member variable (and of course I can keep the class definition close at hand in another window/tab, especially since I would want to refer to the interface anyway).
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  2. #47
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Most modern IDEs should inform you of the type. I guess if you code in notepad it would be an issue.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  3. #48
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by laserlight View Post
    I check the declaration, which would be nearby, or in the corresponding header if it is a member variable (and of course I can keep the class definition close at hand in another window/tab, especially since I would want to refer to the interface anyway).
    I think it is a very bad idea to make the clarity of the code rely on an IDE. Not a big portability/compatibility fan, eh?

    Your method works only on C++ (assumption number 1) object-oriented (assumption number 2) code where all declarations are one click away (assumption number 3) using a complex IDE (assumption number 4).

    Since I work with multiple languages, use both object-oriented and procedural programming, write both extremely low-level and high-level code and use a different IDE on different environments and projects, I would go nuts if I didn't use Hungarian notation.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  4. #49
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by maxorator
    I think it is a very bad idea to make the clarity of the code rely on an IDE.
    I agree, but the clarity of the code does not rely on an IDE.

    Quote Originally Posted by maxorator
    Your method works only on C++ (assumption number 1)
    Yes, I think that whether Systems Hungarian notation is suitable or not definitely depends on the programming language, since we are looking at a convention that replaces a type system.

    Quote Originally Posted by maxorator
    object-oriented (assumption number 2)
    This is not a necessary assumption. From what I see, what is necessary would be local scope and a type system as language features.

    Quote Originally Posted by maxorator
    code where all declarations are one click away (assumption number 3)
    Yes, I think that good programming practices should be applied here. There may be an issue for object oriented programming languages where method definition must be inline with the class definition, but from my experience it is not a problem since someone looking to understand the class would typically consider its data members before digging deep into the internals of any method.

    Quote Originally Posted by maxorator
    using a complex IDE (assumption number 4).
    This is not a necessary assumption, but I agree with indigo0086 that it can help.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #50
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    If he likes HN, that's all well and good, but code has and will be written clean, clear, and understandable without it.
    Here to Deceive, Inveigle, Obfuscate Since 1945

  6. #51
    Making mistakes
    Join Date
    Dec 2008
    Posts
    476
    I think most programmers hate typing. I don't, but if you prefix every single variable with sz or lp, either you will choose a worse name or you'll have to type more.

  7. #52
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by maxorator View Post
    Your method works only on C++ (assumption number 1) object-oriented (assumption number 2) code where all declarations are one click away (assumption number 3) using a complex IDE (assumption number 4).
    This is ridiculous. Even the simplest text editor has a "find all" function which will do almost as well for this, and if you are working with a bunch of files, then you are a computer programmer and have to be able to track down declarations quickly and competently, somehow*. I cannot believe you even pretend to function on a daily basis without doing that. You can tack all the prefixes you want onto a struct name, but it you will never be able to describe the struct usefully that way. You have to *find* the declaration.

    I have nothing against this "hungarian notation" or any other personal preference vis, variable names, just that I read this post and almost spit coffee all over the screen it is so "off the deep end", logic wise.

    *eg, you should have written a simple generic program to do it years ago. Or something. Although it might be exciting, I very much doubt that many programmers are routinely called away to work on something on a completely alien system and allowed to bring no absolutely no tools. Do they drive you to site blindfolded? This is a serious perversion of the concept "portable".
    Last edited by MK27; 05-14-2009 at 10:36 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #53
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by MK27 View Post
    This is ridiculous. Even the simplest text editor has a "find all" function which will do almost as well for this, and if you are working with a bunch of files, then you are a computer programmer and have to be able to track down declarations quickly and competently, somehow*. I cannot believe you even pretend to function on a daily basis without doing that. You can tack all the prefixes you want onto a struct name, but it you will never be able to describe the struct usefully that way. You have to *find* the declaration.
    I was talking about Systems Hungarian notation, so I agree with your opinion on Apps Hungarian notation.

    I think it saves a bunch of time not having to search for the variable declaration just to find out what basic type it is. By complex IDE I meant that it somehow tells you the type of a variable when you either move your mouse on it or type it plus the class browser and all such tools.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  9. #54
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by Brafil View Post
    I think most programmers hate typing.
    As opposed to what, point and click/drag and drop? I like typing and hate when the IDE gets in the way of that, which seems to be the primary role of an IDE.

  10. #55
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by medievalelks View Post
    As opposed to what, point and click/drag and drop? I like typing and hate when the IDE gets in the way of that, which seems to be the primary role of an IDE.
    I'm exactly the opposite.
    "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

  11. #56
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    medievalelks is right. I love typing. Right now I'm doing a lot of reading (about programming) and I have to keep making up silly messages for cboard so that I can stay awake and concentrate. Seriously. I can sit up all night and program, but if I'm just reading, I start to loose focus after about an hour and have to use my mind* some other way for a while to get it back.

    *and body. Ever see those proporationate drawings that map dedicated brain volume to anatomy? Each hand is about twice the size of the torso. Even wierder: learning to use the mouse with my left hand (so I can switch) made my ollie's (skateboard trick) better. The next time you see skateboarders in a bowl, watch what some people are doing with their hands at the same time...extending, contracting, and twisting the fingers.
    Last edited by MK27; 05-15-2009 at 11:18 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  12. #57
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Am not trying to bump the thread; was actually going to pose the OP question. When I started Windows coding in 85 Hungarian notation was enforced and it kinda "stuck". For the most part I have purged myself of it but I still preface Ints with n and so on, mostly out of long habit.

    As for if it is useful I have seen cases when inheriting someone elses code where it was a life-saver and have seen an equal number of cases where it just got in the way. I do however agree that needing an IDE to know what a variable type is is basically lame but that is how some folks get through their day and would be lost without the hand-holding that an IDE provides. If it makes them a more productive (if limited) coder, I am all for it. After working in enough environments where IDEs simply do not exist, I am accustomed to just using a good programmers editor and my own common sense....YMMV...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  13. #58
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Personally I've had to do a file search in the files of a huge project a few times just to find out the type of some PODs. It is annoying. Also I've seen code where in subsequent structures there is a variable "filename", where it is a char array in the first structure and a char pointer in the second structure. Another thing that can be frustrating is when you don't know the level of indirection of a variable (the number of "p"-s in front of the variable elegantly solves that problem when using systems hungarian notation). This is only a small fraction of headaches that the absence of hungarian notation has caused me.
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  14. #59
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by maxorator View Post
    Personally I've had to do a file search in the files of a huge project a few times just to find out the type of some PODs. It is annoying. Also I've seen code where in subsequent structures there is a variable "filename", where it is a char array in the first structure and a char pointer in the second structure. Another thing that can be frustrating is when you don't know the level of indirection of a variable (the number of "p"-s in front of the variable elegantly solves that problem when using systems hungarian notation). This is only a small fraction of headaches that the absence of hungarian notation has caused me.
    The source of your headache is not the lack of Hungarian notation but the fact that the code is stupid in general.

    In general there is no reason to care what type a variable is, other than to understand what sort of interface it conforms to. A char array and a char pointer are basically the same from a usage standpoint -- the fact that you need to know the difference indicates some deeper problem.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  15. #60
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I don't know; there is just something about being able to know what a variable type is with a single glance rather than a lookup or other chicanery but we are all products of the paths that we have walked. I have worked placed that fired you for NOT doing it and others that would care less if the variable type had HN or worse if the HN is wrong (variable type changed after original composition. Often I have however seen where even if you could find the variable, you had to dig and dig to find it, becoming more irritated at spending time when a single character would have answered the question. Even now with UNIX tools (find/grep/et al) it can take more time than it should. And any time you are on a schedule, time is money. I am not necessarily arguing for HN, just wondering where the rest of you are. It seems more like "wild west" projects are the first to dispose of it (along with many other kinds of "process")..
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

Page 4 of 5 FirstFirst 12345 LastLast
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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21