Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Good Examples of Hungarian Notation? [closed]

This question is to seek out good examples of Hungarian Notation, so we can bring together a collection of these.

Edit: I agree that Hungarian for types isn't that necessary, I'm hoping for more specific examples where it increases readability and maintainability, like Joel gives in his article (as per my answer).

like image 262
Lance Roberts Avatar asked Oct 14 '08 17:10

Lance Roberts


1 Answers

The problem with asking for good examples of Hungarian Notation is that everyone's going to have their own idea of what a good example looks like. My personal opinion is that the best Hungarian Notation is no Hungarian Notation. The notation was originally meant to denote the intended usage of a variable rather than its type but it's usually used for type information, particularly for Form controls (e.g., txtFirstName for a text box for someone's first name.). This makes the code less maintainable, in terms of readability (e.g., "prepIn nounTerms prepOf nounReadability") and refactoring for when the type needs to be changed (there are "lParams" in the Win32 API that have changed type).

You should probably consider not using it at all. Examples:

  • strFirstName - this can just be firstName since it's obvious what it's for, the type isn't that important and should be obvious in this case. If not obvious, the IDE can help you with that.
  • txtFirstName - this can change to FirstNameTextBox or FirstName_TextBox. It reads better and you know it's a control and not just the text.
  • CAccount - C was used for class names in MFC but you really don't need it. Account is good enough. The uppercase name is the standard convention for types (and they only appear in specific places so they won't get confused with properties or methods)
  • ixArray (index to array) - ix is a bit obscure. Try arrayIndex.
  • usState (unsafe string for State) - looks like "U.S. State". Better go with state_UnsafeString or something. Maybe even wrap it in an UnsafeString class to at least make it type-safe.
like image 186
4 revs, 3 users 86% Avatar answered Sep 23 '22 05:09

4 revs, 3 users 86%