简体   繁体   中英

Abbreviation in system .Net generated code

While Microsoft suggests to avoid using abbreviations in code, why do the system generated code of Event Handler contains following line?

private void TextBox1_TextChanged(object sender, EventArgs e)

Notice that "e" is in abbreviation. Does this rule not apply to Event Handlers?

No, its not a Hungarian notation. It just an abbreviated name (as mentioned in comments above) And you better to read more about Hungarian notations.

Hungarian notation is an identifier naming convention in computer programming, in which the name of a variable or function indicates its intention or kind.

Ex: string strName="";
here you mention the type of variable , as a part of the variable name. But in modern days , its useless due to different reasons.

  • You can find the type through the IDE easily, so, no need to mention it on name
  • difficult to change the variable type, need to change its name too.

and many more.

Your question has been well-answered above, but I'll throw in my $0.02 on Hungarian Notation.

There is a great article that touches on Hungarian Notation Here . It addresses some misconceptions about Hungarian notation, in particular what is it supposed to be , as opposed to what it is often assumed to be.

The example in the answer from @Hiran is what is is often assumed to be, and Hiran is quite correct: putting the str prefix on string strName is redundant with a modern IDE.

The main take-away from the linked article is from this paragraph:

In Simonyi's version of Hungarian notation, every variable was prefixed with a lower case tag that indicated the kind of thing that the variable contained.

For example, if the variable name is rwCol, rw is the prefix.

I'm using the word kind on purpose, there, because Simonyi mistakenly used the word type in his paper, and generations of programmers misunderstood what he meant.

I understand that Microsoft's guideline on not using Hungarian Notation was more about what it has become (prefixing the variable name with the variable type).

Thus, in the original intent, "Hungarian Notation" could be to use string pName (for 'productName') instead of string name .

As to the original question, the same declaration in Hungarian Notation might be more like:

private void TextBox1_TextChanged(object sender, EventArgs tcArgs)

Given that these EventArgs e are in the Event Handler, I'm not convinced such notation is particularly useful in this specific case .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM