Hungarian Notation vs. IntelliSense
-
All true. I don't use Visual Assist (shame on me, I know), but I do use the 'p', 'm_', 'g_', 'n', 'sz' prefixes. Unlike some of the sxuggestions in the guide to Hungarian Notation in MSDN I don't absolutely mad and notate absolutely everything about a variable. > Andrew.
Sounds like you're taking a sensible approach - doing it when it makes sense instead of because it's the 'done thing'. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.
-
One reason I use the "m_":
void MyClass::SetValue(int nValue)
{
m_nValue = nValue;
}If I didn't use the 'm_' I'd have to think of different names for the member variable and the parameter. WAY too hard ;) cheers, Chris Maunder
... And of course, it's even harder to use this->nValue = nValue; ;) I personally don't like Hungarian Notation, but it's almost a standard in Win32 programming. What I hate the most is the Win32 typedefs like: LPCTSTR, LPTSTR, LPxxx etc. X|
-
The purpose of Hungarian notation is to include the variable's type in its name so programmers know the type whenever the variable is used. Have any of you using Visual C++ 6 hovered the cursor over a variable? Henry casually scans the room searching a fire extinguisher.
-
The purpose of Hungarian notation is to include the variable's type in its name so programmers know the type whenever the variable is used. Have any of you using Visual C++ 6 hovered the cursor over a variable? Henry casually scans the room searching a fire extinguisher.
I do not think IntelliSense has much to do with it. I use more hungarian now with VC than before. I agree with Chris, m_ is good to note scope and p for pointers. Beyond that I rather use a discrptive title than religiously following some dictate. However most of what I write is not code that any programmer that does not know the purpose of the code should be editing. If they do, then usually they know what the variable type should be anyways. Code that is more general purpose I try to follow "standards" if they make sense.
-
One reason I use the "m_":
void MyClass::SetValue(int nValue)
{
m_nValue = nValue;
}If I didn't use the 'm_' I'd have to think of different names for the member variable and the parameter. WAY too hard ;) cheers, Chris Maunder
Aside from Hungarian (I do like the m_ notation), I like to name parameters with a trailing underscore.
void MyClass::BigFunction(int nValue_)
{
// ... reams of code
m_nValue = nValue_; // trailing '_' helps me remember that
// nValue_ is a parameter, not a local
// variable.
} -
The purpose of Hungarian notation is to include the variable's type in its name so programmers know the type whenever the variable is used. Have any of you using Visual C++ 6 hovered the cursor over a variable? Henry casually scans the room searching a fire extinguisher.
One more aspect of naming, it's easy to look at lists of names (for instance in a .map file or dumpbin output) and tell what's what. You can always use
UndecorateName()
to get some of this information but it's incomplete and inconvenient. It's good to be able to grep through code and such for global variables, member attributes, functions, local variables, function arguments, etc. Thus, I get most mileage from the stuff before the underscore (I usem_
,s_
(static member),g_
(global),sc_
(static const member),gc_
(const global), and (rarely)mc_
(const member)). I have gotten in the habit of using Hungarian everywhere because it helped me out when I was first writing Windows code, but it is much less useful to me now. More of a bad habit that I haven't broken or learned to moderate (is there a local chapter of Hungarians Anonymous in Tennessee? :-)). -
All true. I don't use Visual Assist (shame on me, I know), but I do use the 'p', 'm_', 'g_', 'n', 'sz' prefixes. Unlike some of the sxuggestions in the guide to Hungarian Notation in MSDN I don't absolutely mad and notate absolutely everything about a variable. > Andrew.
Same here.
-
Aside from Hungarian (I do like the m_ notation), I like to name parameters with a trailing underscore.
void MyClass::BigFunction(int nValue_)
{
// ... reams of code
m_nValue = nValue_; // trailing '_' helps me remember that
// nValue_ is a parameter, not a local
// variable.
}Parameters are local variables.
-
The purpose of Hungarian notation is to include the variable's type in its name so programmers know the type whenever the variable is used. Have any of you using Visual C++ 6 hovered the cursor over a variable? Henry casually scans the room searching a fire extinguisher.
Hi, Some of us have to compile our C++ code on: Windows, UNIX, VMS, AS400, Tandem and MVS. And my mouse don't fly ;) Old Simon
-
I used to love Hungarian notation, but the MSDN is proof of it's inadequacies. How many basic types have changed ( wParam for example ) and now have names that imply they are something they are not ? I always use p for a pointer, otherwise I find it to be of no value. Visual Assist tells me what type a variable is anyhow, and I have no use for looking over source code on paper, where I cannot edit it if I want to. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.
Some of the worst C++ I have seen is in the MFC source and to a lesser extent on MSDN, but to be fair quite a lot of it is quite old. Then again, if you want poor code just look at SAP (on second thoughts, better not - it's very depressing). Old Simon
-
... And of course, it's even harder to use this->nValue = nValue; ;) I personally don't like Hungarian Notation, but it's almost a standard in Win32 programming. What I hate the most is the Win32 typedefs like: LPCTSTR, LPTSTR, LPxxx etc. X|
What I hate the most is the Win32 typedefs like: LPCTSTR, LPTSTR, LPxxx etc. Why? They are obvious? Old Simon
-
I think Mike Dunn wrote a shell extension for that. :-D
What more can I say but... ROFL! ;P Andy Metcalfe - Sonardyne International Ltd
(andy.metcalfe@lineone.net)
http://www.resorg.co.uk"I used to be a medieval re-enactor, but I'm (nearly) alright now..."
-
What I hate the most is the Win32 typedefs like: LPCTSTR, LPTSTR, LPxxx etc. Why? They are obvious? Old Simon
The L is the annoying bit for me, since it's a legacy thing from 16 bit days. Of cource you could argue that it'll have a second wind with win64...
-
The L is the annoying bit for me, since it's a legacy thing from 16 bit days. Of cource you could argue that it'll have a second wind with win64...
I dropped the "l" prefix when I started with VC 4.0. Most of the others still make sense though I do get irritated that Win32 and MFC use different prefixes! Andy Metcalfe - Sonardyne International Ltd
(andy.metcalfe@lineone.net)
http://www.resorg.co.uk"I used to be a medieval re-enactor, but I'm (nearly) alright now..."
-
Are you using PAPER.NET? ;)
-
One reason I use the "m_":
void MyClass::SetValue(int nValue)
{
m_nValue = nValue;
}If I didn't use the 'm_' I'd have to think of different names for the member variable and the parameter. WAY too hard ;) cheers, Chris Maunder
Hello Chris, what about this.nValue = nValue :)
-
Hello Chris, what about this.nValue = nValue :)
Uh Oh, should have been this->nValue = nValue:| :|
-
Sounds like you're taking a sensible approach - doing it when it makes sense instead of because it's the 'done thing'. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.
Yeah, same with me. I use Hungarian notation as a tool, not a religion. I have looked at some of my old code with H-N and some of my old code without it. I was able work with the H-N code faster and get my job done faster. So I use it. It is simple as that. Tim Smith Descartes Systems Sciences, Inc.
-
One more aspect of naming, it's easy to look at lists of names (for instance in a .map file or dumpbin output) and tell what's what. You can always use
UndecorateName()
to get some of this information but it's incomplete and inconvenient. It's good to be able to grep through code and such for global variables, member attributes, functions, local variables, function arguments, etc. Thus, I get most mileage from the stuff before the underscore (I usem_
,s_
(static member),g_
(global),sc_
(static const member),gc_
(const global), and (rarely)mc_
(const member)). I have gotten in the habit of using Hungarian everywhere because it helped me out when I was first writing Windows code, but it is much less useful to me now. More of a bad habit that I haven't broken or learned to moderate (is there a local chapter of Hungarians Anonymous in Tennessee? :-)).I also used HN when I started programming Windows but have since stopped. I still use g_ and m_ though.
-
Uh Oh, should have been this->nValue = nValue:| :|
I really don't like this particular style. I just don't find it clear. One of our (former) developers used to use this->SomeFunction() to force Intellisense to display the members of the class while he was coding (he hadn't discovered CTRL+SPACE). Everybody on the team used to hate reading his code. Just one of them things I guess - in his own words "much badness" X| Andy Metcalfe - Sonardyne International Ltd
(andy.metcalfe@lineone.net)
http://www.resorg.co.uk"I used to be a medieval re-enactor, but I'm (nearly) alright now..."