Hungarian Notation in .Net - Yes or No?
-
I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines:
Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate.
It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------I just stick to whatever I feel like.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Chris Maunder wrote:
memberId
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Cheers, Vıkram.
After all is said and done, much is said and little is done.
I used to use
ID
but because of FxCop, I changed my habit toId
now.Luis Alonso Ramos Intelectix Chihuahua, Mexico
-
yay for camelCase!
I'm largely language agnostic
After a while they all bug me :doh:
Whereabouts in the Midwest are you, Limey? I've been a Limey in Central California for almost 9 years now...
Sunrise Wallpaper Project | The StartPage Randomizer | A Random Web Page
-
I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines:
Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate.
It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------I might be in minority but I don't really care. If you are using VS2005 Hungarian notation adds little value. Just put the cursor over the object and the type is displayed. Honestly I'm not consistent with my naming. I might have a text box name txtBox1, txtName, txt or just "x" (if I'm using it in a loop). Since I do ASP.Net I don't have to many 10,000 line methods because all the code has to run during a postback. I'm the same way with my database fieldnames, I just don't care. You may call it laziness but I think too many programmers an Anal about this stuff. Like I said before, if I want to know what type something is, I just put the cursor on it.
I didn't get any requirements for the signature
-
I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines:
Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate.
It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------As others have pointed, I try to do as the framework/language does. For C++ (which I rarely do these days), I use hungarian notation. For C# I try to use the .NET notation (to be consistent with the framework). I've got used to it, and it works fine for me. I remember when I started with C#, I used hungarian notation. But it just didn't feel right mixing it with .NET's variable names. I think that's what made me change. And with well-chosen variable names, the type can be deducted from the name. The conclusion here, is do it however you want to do it, but just try to be consistent (worse than any standard is no standard).
Luis Alonso Ramos Intelectix Chihuahua, Mexico
-
Chris Maunder wrote:
memberId
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Cheers, Vıkram.
After all is said and done, much is said and little is done.
Vikram A Punathambekar wrote:
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc
-
I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines:
Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate.
It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------I only use hungarian-notation because it's what I'm used to - but I much prefer: variableName as opposed to dwVariableName I think the first is much easier to read. There's already been alot of very good points on how IDE's can help out more these days. If I'm doing Windows C/C++ code then I'll use hungarian, otherwise I'll use camel-case. http://ootips.org/hungarian-notation.html[^] There was an article floating around on the web a while back about how Hungarian-notation as we know it is not very useful. There is another variant (IIRC called 'apps hungarian' which names variables after their usage rather than their base-type. http://blogs.msdn.com/larryosterman/archive/2004/06/22/162629.aspx[^] might be interesting to you..
-
I've been at my Job(1st since graduating college), for about a year now, and I dont know what I'd do without the notation. I'm mostly dealing with code that has somewhere along the lines of 10000 line functions. Having to scroll up to check types for variable types only used once would be beyond a pain in the a**. So hurray for Hungarian Notation for saving me precious time and facilitating my laziness to scroll up.
[Insert Witty Sig Here]
VonHagNDaz wrote:
I'm mostly dealing with code that has somewhere along the lines of 10000 line functions. Having to scroll up to check types for variable types only used once would be beyond a pain in the a**. So hurray for Hungarian Notation for saving me precious time and facilitating my laziness to scroll up.
Wow! Sounds like you should be spending time refactoring the code rather than using Hungarian Notation. Seriously. If a method is over a couple of dozen lines then you should look at refactoring it.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
I was never into Hungarian Notation to begin with, but... Look at C# 3.0's "var" keyword. Examples here[^] about 1/2 down. I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer. Now, from what I've heard from others, the var keyword is really just a convenience for not typing in the complete type (which I disapprove of), but I suspect there are better uses. Marc
Marc Clifton wrote:
I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer.
And if the
var
is holding an anonymous type? What would you put for the Hungarian Notation. I don't think I would ever usevar
for known types.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
VonHagNDaz wrote:
I'm mostly dealing with code that has somewhere along the lines of 10000 line functions. Having to scroll up to check types for variable types only used once would be beyond a pain in the a**. So hurray for Hungarian Notation for saving me precious time and facilitating my laziness to scroll up.
Wow! Sounds like you should be spending time refactoring the code rather than using Hungarian Notation. Seriously. If a method is over a couple of dozen lines then you should look at refactoring it.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
"Don't change it, the code works. Why would we change existing code if it works? If its already done, we shouldn't have to go back and rework it. It's worked this long, surely there is no need to fix what isnt broke..." - Manager
[Insert Witty Sig Here]
-
VonHagNDaz wrote:
I'm mostly dealing with code that has somewhere along the lines of 10000 line functions. Having to scroll up to check types for variable types only used once would be beyond a pain in the a**. So hurray for Hungarian Notation for saving me precious time and facilitating my laziness to scroll up.
Wow! Sounds like you should be spending time refactoring the code rather than using Hungarian Notation. Seriously. If a method is over a couple of dozen lines then you should look at refactoring it.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
That's 24 lines. Wow. I can imagine your code would be so highly componentized as to have to trace 50 layers down the call stack in order to find out what you're actually doing. I hope you're exaggerating -- to me, anywhere up to 150 lines sounds a bit more realistic.
-
Vikram A Punathambekar wrote:
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc
-
Marc Clifton wrote:
I think the var keyword might be reason to bring back Hungarian Notation, because you have no idea what type the var is unless you look at the initializer.
And if the
var
is holding an anonymous type? What would you put for the Hungarian Notation. I don't think I would ever usevar
for known types.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
I agree, although I can see myself using var for long types like
Dictionar<EventHandler<SomeArgs>, KeyValuePair<int, string>>
. Typing long stuff like that twice in the declaration is superfluous. Sometimes I wish we'd just adopt Ruby or Boo syntax for that stuff. Something like:Dictionary<...> whatever = new();
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
I recently posted a C# article and as a C++ programmer is wont to do, I used hungarian notation on all my variables. This has generated a bit of discussion in the comments for the article, and not wanting to be completely close-minded about it, I decided to google it. Here's what I've found so far: 0) It seems that Microsoft thinks we should abandon it in favor of "more natural english-like" variable names. The best response to that statement was this little gem: "If Microsoft said I shouldn't comment my code, it wouldn't stop me from doing that, either." I could not have said it better myself. Maybe this outlook by Microsoft is why Vista is such garbage, or why the ORCAS Beta 2 is so transiently reliable. Just because some self-important evangelist from Microsoft says it doesn't make it gold. Translation - this claim is pretty weak. This is from Microsoft's coding guidelines:
Use names that describe a parameter's meaning rather than names that describe a parameter's type. Development tools should provide meaningful information about a parameter's type. Therefore, a parameter's name can be put to better use by describing meaning. Use type-based parameter names sparingly and only where it is appropriate.
It looks to me like they're putting the emphasis on reading code squarely on the end user instead of the developer. Hello!? We're programmers, and we can't be bothered by trying to figure out what type a variable is supposed to be. Sure, code should be easy to read, but that trait is introduced with meaningful variable and function names, not by removing ancillary information about the variables being used. 1) If you change the variable's type, it all of a sudden invalidates the name of the variable. Ever heard of Find/replace (with case matching and whole word turned on)? Besides, I can count on one hand how many times I changed the type of a variable in the last 18 years of C++ work. 2) Puts an emphasis on the type instead of the descriptive identifier name—encourages poor variable names. Ummm, how can a single lowercase character move the emphasis from the following variable name to the type itself. Further, hungarian notation in no way promotes the creation of "poor variable names". I can't recall ever hearing a programmer say, "Yep, using hungarian notation so that means I can skimp on the rest of the variable name." There are other equally invalid reasons put forth by all manner of know-it-alls, but I got bored typing this stuff. ------I used to love Hungarian Notation. But I grew bored, and now subscribe to the train of thought why it is obsolete. Mainly because I only develop in Visual Studio that gives me all of the info I need about a variable. I think the code looks cleaner without it. I also think that problems arise when you have more that 26 types, then you move into multiple character prefixes. My coworkers like Hungarian notation, but they use 'b' to mean both byte and bool. If you name a variable well, it should have all of the information that you need.
-
I hate hungarian notation. Hate, hate, hate, hate... The fact that seven years of coding on a team where it was The Standard have made it almost a habit for me just makes me hate it even more. The original idea was ok: tag variables with codes that indicate what sort of data it will be used for - not a basic compiler-defined type, something that actually makes sense in the app. But that was decades ago, and in the meantime we gained compilers that deal nicely with concise functions, and editors that can make code pretty and easy to read. And so it hangs around, extra baggage for those skilled enough to actually use it right, and yet another opportunity for the lazy to trip us up by throwing any old prefix onto variables. With .NET, Microsoft finally told the Hungarian to hit the road, hired some real programmers, and ditched the madness. It is, quite possibly, my second-favorite .NET feature.
You must be careful in the forest Broken glass and rusty nails If you're to bring back something for us I have bullets for sale...
I agree with you comments about the sort of data, just not the type. I ditched Hungarian notation a while back, but I still like 'p' for pointer, and sometimes a few others. like "is" for a boolean to make the name look like a question etc...
-
I agree with you comments about the sort of data, just not the type. I ditched Hungarian notation a while back, but I still like 'p' for pointer, and sometimes a few others. like "is" for a boolean to make the name look like a question etc...
Paul Watt wrote:
ike "is" for a boolean to make the name look like a question etc...
I've been doing that now as well. isFooEnabled, isDisplayingBars, etc.
Tech, life, family, faith: Give me a visit. I'm currently blogging about: Orthodox Jews are persecuting Messianic Jews in Israel (video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango
-
I agree with you comments about the sort of data, just not the type. I ditched Hungarian notation a while back, but I still like 'p' for pointer, and sometimes a few others. like "is" for a boolean to make the name look like a question etc...
Paul Watt wrote:
"is" for a boolean to make the name look like a question
Yeah, i'm fine with that, 'cause it can actually make the code more readable:
if (isAnOddChoice)
,if (hasNoWhereToRun)
,while (noMatchFound)
, etc. But to me, that's just putting a bit of thought into your naming rather than picking some generic name (e.g.,Success
) and tacking on a prefix. Of course, i'm totally lazy enough to do the latter at every turn, so perhaps my attitude is just a desire to force myself into using better names... ;)----
I don't care what you consider witty, but at least I do not blather on posting nonsense like Jim Crafton.
-- Stringcheese, humbled by Crafton's ability to string together multiple sentences
-
That's 24 lines. Wow. I can imagine your code would be so highly componentized as to have to trace 50 layers down the call stack in order to find out what you're actually doing. I hope you're exaggerating -- to me, anywhere up to 150 lines sounds a bit more realistic.
Cyrilix wrote:
I hope you're exaggerating -- to me, anywhere up to 150 lines sounds a bit more realistic
I said "you should look at refactoring it" not that you MUST refactor it. At a quick glance I can see that the vast majority of my methods fit in one screen. That would be about 30 to 40 lines.
Cyrilix wrote:
I can imagine your code would be so highly componentized as to have to trace 50 layers down the call stack in order to find out what you're actually doing.
Not as far as that, but then my code reuse is way up on what it was when I wrote methods at 100+ lines. Also, I give things meaningful names so it is easy to see what something does without having to go into every method.
Upcoming events: * Glasgow: Mock Objects, SQL Server CLR Integration, Reporting Services, db4o, Dependency Injection with Spring ... "I wouldn't say boo to a goose. I'm not a coward, I just realise that it would be largely pointless." My website
-
Vikram A Punathambekar wrote:
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc
I despise using lower/Camel/Pascal case for an acronym. IMO, acronyms should always be upper case.
Software Zen:
delete this;
-
Vikram A Punathambekar wrote:
I use ID instead of Id. FxCop bugs the hell out of me on that one.
Really? Because I thought the standard with acronyms and abbreviations was to uppercase for the first letter, lower for the rest. Marc
Matlab purists get tied up when you spell it 'Matlab' instead of 'MATLAB'. Apparently, 15 years ago each of those letters meant something and you better well recognize the acronym, dammit!