Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

paulecoyote

Hungarian Notation - no longer necessary?

This topic is 5211 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I didn''t know how old school I was coding until I looked up coding standards on the newer breed of languages (C# and Java). For those who don''t know what that is: http://burks.brighton.ac.uk/burks/foldoc/40/54.htm So... I thought it was good discipline, but it seems that coding standards from both Microsoft and Sun encourage you not to use it. I think that m_ is useful prefix for class variables - esp when reading a hardcopy rather then being assisted by a clever IDE. But I suppose if you prefix "this." before accessing class member variables then thats just as clear. The compiler is likely to optimise out the "this." bit out of the code anyway rather then get a reference to the current object from the current object and then the variable in question. Same argument for s_ for statics I guess - just prepend the class name to make usage clearer. The only thing I can still find to justify is p prefix for pointers (*). This has little meaning or use in C# and Java where you can''t get so muddled with deferencing or pointers to pointers... but in C++ and C I still think a p prefix has a place. Or even a pp for **. Because you REALLY want to know what you are dealing with when it comes to references or pointers - right? And a pointer type is never going to be anything other then a pointer type - it''s not like it''s going to get out of date like if you have iCount... and decide that an integer isn''t big enough so you need to change it to lCount. Thoughts?

Share this post


Link to post
Share on other sites
Advertisement
I used to use a lite version of that notation. After a while, I wondered what the point in using the m_ notation on member variables is if almost EVERYTHING is going to be a member variable. And then I stopped using the notation letters before each variable too.. I considered that it was obvious as it is, but I could always move the mouse cursor over it anyways (which takes less time overall than typing m_i whatever everytime).

Pointers to pointers will cause a compile error if used incorrectly, so don''t need to worry about those. I never use "this" either, unless using overloaded class operators or copy constructors. I always thought that some kind of notation on the parameters for every function would make more since, easy to glance at the code and know what''s going to be affected. But that''s just me, if I code with a group of people then I''ll be happy to accept hungarian style.

Share this post


Link to post
Share on other sites
I think I''m starting to think along the same lines. It''s looking at code without a fancy editor (notepad, vi, whatever) or printed-out that doesn''t have compiler errors thrown up at you that it''s usage could be a bit ambiguous. The only prefix I can justify there is good ol'' p.

Coding in Java and C# - you would not usually come across a situation that used a pointer instead of a reference anyway.

Share this post


Link to post
Share on other sites
I never liked hungarian notation and never used it. Also, when I was beggining with C++, I wasn't working with IDE that would show me the type of the var. And I didn't have any troubles with it. I think, you can guess from the context what type is that var, and if you're coding - you would have to be stupid to use a var without knowing what type and purpose is it (Well - don't know how about others - but I'm not coding blindly - just to guess what is some var for just of its name - I have to look at the comment by the var to see what is it for - and at that time, I can look few pixels to the left and I can see the type of it.).

Also - if you see
if (time >= 1.0) ...   
then it is clear, that 'time' is a double.

Oxyd


"It is better to listen than to speak"
    -- Abba Nisterus


[edited by - Oxyd on June 10, 2004 12:40:09 PM]

[edited by - Oxyd on June 10, 2004 12:41:05 PM]

Share this post


Link to post
Share on other sites
Hungarian notation completely obfuscates code and renders it virtually unmaintainable. The classic example is the fact that you still see LPCSTR ( long pointer to a c string ) scattered throughout the Win32 SDK. Long pointers disappeared along with 16 bit Windows many years ago. Thanks to hungarian notation we now see LPCSTR scattered all over the place even though it is really a non-existant type.

Anyhow, most compilers now a days generally are very informative with type bending errors. Hungarian has absolutely no purpose anymore.

Share this post


Link to post
Share on other sites
Greetings,

Though I am not keen on the complete use of Hungarian notation (particularly of what I see in VC++ 6.0), I do use the following notations which I find useful when using grep to isolate things (like all class members that are pointers)...

class Foobar
{
public:
int m_Value;

public:
int* mp_Value;
};

The use of the "m_" and "mp_" also allow me to clearly disguish local variables in a member function from actuall class members and function arguments (which, btw, are denoted by the first letter capitalized, prefixed by a lower-case ''p'' if it is a pointer to something, or prefixed by a lower-case ''r'' if it is a reference to something).

Having an IDE which indicates type is great, but not all programmers use such IDE''s. And also, a 10 page print out of a member function would tell you if "foobar" belongs to the class, is an argument, or a local variable. (Oh, and dont get me started on global denotation

I guess, in conclusion, use what you think is best. IMHO, it never hurts to have you variable names be a bit more exacting; of course, where to draw that line will always be debated.

Regards,
Ro


Eagles may soar, but a ferret will never get sucked into a jet engine!

Share this post


Link to post
Share on other sites
A little doesn''t hurt - I agree with people here - pointers, sometimes arrays, member/static is sometimes useful.

I find myself often using ntimes and bfinished and similar just for simple integers and booleans used within my code, but that''s about it.

So simplified, its useful.

Share this post


Link to post
Share on other sites
If you avoid using pointers as much as possible (e.g. use references and containers such as vector) you can do away with the p too for most normal code.

Share this post


Link to post
Share on other sites
I use m_ and pp but nothing else. In particular I don''t use C in front of class names.

I think m_ is fine because it''s not tying to signify type but rather scope. Yes you could use this-> instead but that''s a bit to wordy for me. I don''t distinguish between ordinary members and static members.

I don''t think plain pointers need a p prefix. The fact that you''re using -> instead of . is plenty to tip the reader off that this is a pointer. I''m not sure why I continue to use pp. It just works for me.

I try real hard not to use globals. On those rare occasions I do use them I create a Global namespace, i.e. Global::some_var.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!