Hungarian coming back into fashion?

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
8,318
Location
Chesapeake, VA
Programming Experience
10+
It's not a big enough sampling, but I've noticed a few recent C# posts both here and in DIC where the posters have been using the Hungarian naming convention in their code. And it's not just the leading underscore prefix to denote member variables, but rather the type defining prefixes like dbl, str, bool, lst, dic, etc.

Personally, this drives me up the wall because if people are going to use Hungarian, they should use Hungarian the way it was originally meant to be used. n for integer, not int. rg for array, not are. s for string, not str. d for double not dbl. f for float, not flt. And fully spelled out typenames for everything else. Eg. combobox for a ComboBox, not cmb. Checkbox, not chk. datetime, not dt.

Anyway, does anyone know why Hungarian notation seems to be icoming back into fashion? Is there a trending tutorial or library that is pushing this? Or is is VB6 programmers who had come up with that bastardized Hungarian moving on from VB.NET and going into C# who are bringing along their old naming conventions?

Hungarian notation is not really needed for C# (and VB.NET) because of the nature of the IDEs and text editors we use with the language. The editor and debugger can now show us the type of the variable without resorting to using Hungarian. And it's not like we do paper code reviews anymore. People do code reviews with their text editors. And the correct modern style of writing code discourages huge files, and huge methods. So anything declared will either be on the same screen, or at worse, just a few pages away.

The reasons why Hungarian was invented by Charles Simonyi was to help denote type information to aid in debugging and reasoning with code. The MS Windows org adopted it because it was really helpful, specially when doing low level debugging in the kernel when all you would have at times is just the symbol name. The MS Office team adopted the idea, but instead of is my the prefixes to denote the low level type, they used it to denote semantic usage of the variable.
 
Seen a few, both here and other places, but not many. I was thinking the same, older VB coders bringing bad habits into C# ?
There's a slight chance the later use of inferred types is bringing this up again in some minds (thinking about var something), to better keep track visually later in code, but I'm opposed to Hungarian notation either way.

I tend to keep the control 'type' name in my hobby projects though, like "UpdateButton", "SomethingGrid" etc, but don't think of that as a Hungarian notation, more like a reference to functionality.
 
So do these bother you too?

void OFDSetSourceUpOneDirectory_Button_Click
void DriveListing_ListBox_Selected
void SourceFolderDialogWindow_Initialized
void DirectoryListingListBox_DoubleClick
void SetSourceDirectory__DoubleClick_Button
void SetSourceDirectory_Button_Click

Or is just when you specifically start off with var __myPerfectVariable?
 
One of the things I feel people are missing in C# is a good separator for between words, just as I have above. It helps to make long named objects a bit more readable when separated by _.
 
I don't mind snake case names. In fact, I'm starting to use them more and more often in my unit tests.

I also don't mind the underscore prefix to denote a member variable. "_myPerfectVariable". What drives me nuts is:
C#:
int [] _intDataArray;

If you are going to use Hungarian, use it the right way:
C#:
int [] _rgnData;
 
Yup... just like my issues with Java programmers trying to write C# code the Java way.
 
I was reading the code on dic. And I was all but ready to headbutt my screen. It frustrates me more when people can't download a zip of code without breaking it upon opening it. Bothers me more than any Hungarian.
 
Ah yes, you hate when I use the likes of if (objectY.ActualHeight.Equals(10)) etc.

Sometimes, its habit from writing in other languages. As you know I am no longer primarily writing C# code, and am now writing much more in various languages than what I used too.
 
As a very experienced C++ programmer that you are; you too know what it's like to develop bad habits from other languages and carry them on into other frameworks where they don't fit with the norm of common usage, yet achieve the same outcome. EDIT: Point being, you recall what you told me why you preference C#, right?

I do write Java, but i am not its number one fan. I use it where its needed best.

The whole concept of Hungarian coming back, well I think it's just a writing style more than it is anything to do with old habits or those vb'ers.
 
Yes, but what is driving that style coming back?

Do you think Pythonistas will accept Hungarian being used in production Python code? From what I've seen in the past, they have a strict style guide for everything.
 
I don't know exactly, I guess, ideology and appetite? Why do any of us write code the way that we do?

All it takes is someone to share a style of code with another person and then a trend starts based on how it is interpreted and first visualised, copied and the concept is reproduced. Perhaps it's appetising or aesthetically pleasing to some. Regardless if we like it or not, it won't stop people writing like that. Besides its a trend that I see now and again, and it comes and goes on these forum boards.

It shouldn't bother you to much. I don't write like most people, and neither do you. So why does it bother you what way they write?
 
It bothers me because it looks like someone is teaching incorrect Hungarian, the same way it bothers you when someone is using WPF incorrectly.
 
Back
Top Bottom