-1

I have recently started working in a system that includes the data type in the fieldnames for every record. I'm writing up the documentation for this system (in particular the coding conventions), and as a history lesson, I wanted to include a reference to this style of naming convention.

In the past, I know it was very standard to use names like

dim strName
dim intAge
dim fltIncome

To help keep track of datatypes in dynamically typed languages (VBS in the case above). I also, know that this convention was actually named after somebody who wrote a lengthy description about why this is a good idea.

Does anyone know the name of this convention, or have good references they could share?

Jefferey Cave
  • 2,507
  • 1
  • 27
  • 46
  • 1
    You're thinking of [Hungarian Notation](https://en.wikipedia.org/wiki/Hungarian_notation). Not a fan of it, but it served a purpose in VBScript where data type wasn't obvious. But the thing about VBScript is you could start off with an integer and that variable could then be a date or string so hard wiring the type in the name in my opinion doesn't make sense. - [Why shouldn't I use "Hungarian Notation"?](https://stackoverflow.com/q/111933) – user692942 Jun 14 '22 at 16:01
  • I use a small "o" in front of object names and "a" or "Arr" in front of array variables. Otherwise, I find no benefit in using HN in VBScript. – LesFerch Jun 14 '22 at 17:35
  • 1
    Hungarian Notation... yes that is the beast. Like it or not, I find myself typing up documentation and a history lesson appears to be in order – Jefferey Cave Jun 15 '22 at 04:46
  • 1
    To be absolutely clear using the data type as a prefix to a variable is a form of Hungarian Notation specifically Systems Hungarian. – user692942 Jun 17 '22 at 10:16

1 Answers1

-1

COM doesn't use Hungarian Notation at all. The Windows API does. And its useful enough. I've bolded the pat below that refutes Hungarian Notation in COM.

This is from https://learn.microsoft.com/ms-my/previous-versions/windows/desktop/automat/naming-conventions

Choose names for exposed objects, properties, and methods that can be easily understood by users of the application. The guidelines in this section apply to all of the following exposed items:

Objects — implemented as classes in an application.

Properties and methods — implemented as members of a class.

Named arguments — implemented as named parameters in a member function.

Constants and enumerations — implemented as settings for properties and methods.


Use Entire Words or Syllables

It is easier for users to remember complete words than to remember whether you abbreviated Window as Wind, Wn, or Wnd.

When you need to abbreviate because an identifier would be too long, try to use complete initial syllables. For example, use AltExpEval instead of AlternateExpressionEvaluation.

Use                    Don't use

Application                App

Window                     Wnd

Use Mixed Case

All identifiers should use mixed case, rather than underscores, to separate words.

Use                      Don't use

ShortcutMenus        Shortcut_Menus, Shortcutmenus, SHORTCUTMENUS, SHORTCUT_MENUS

BasedOn                  basedOn

Use the Same Word Used in the Interface

Use consistent terminology. Do not use names like HWND that are based on Hungarian notation. Try to use the same word users would use to describe a concept.

Use                   Don't use

Name              Lbl

Use the Correct Plural for the Class Name

Collection classes should use the correct plural for the class name. For example, if you have a class named Axis, store the collection of Axis objects in an Axes class. Similarly, a collection of Vertex objects should be stored in a Vertices class. In cases where English uses the same word for the plural, append the word "Collection."

Use                          Don't use

Axes                     Axiss

SeriesCollection         CollectionSeries

Windows                      ColWindow
user18521918
  • 102
  • 1
  • 1
  • 3
  • The OP asked what the name is, there is already a canonical answer for this [here](https://stackoverflow.com/a/36896626/692942). – user692942 Jun 15 '22 at 11:03
  • @user692942 But it is a canonical answer to a different question. He is not asking about hungarian notation. In VBScript all variables at `pvarName` using hungarian notation. – user18521918 Jun 15 '22 at 18:15
  • 1
    The OP question was what is that naming convention called, the answer is "Hungarian Notation". The question explains what it is. What COM and Windows API have to do with that simple question I do not know. – user692942 Jun 15 '22 at 19:08
  • @user692942 **It is not hungarian notation**. A VBScript, if using hungarian, is `pvar`. A pointer to a variant. So if using hungarian all variables will be prefaced with `pvar`. `pvarX = 5`. – user18521918 Jun 15 '22 at 19:26
  • 1
    Seriously you’re arguing semantics? Just read the Wiki it doesn’t need to be that prescribed, Hungarian Notation is used to describe variables describing their data type so `strTest` for a string and `iTest` for an integer. We are talking about VBScript not Windows API or COM. There are lots of examples of that notation being used as a "programming style". – user692942 Jun 15 '22 at 19:35
  • @user692942 Hungarian is a **specific** example of that style, with rules. – user18521918 Jun 15 '22 at 19:38
  • Its name is the style chosen by the VBA sample code documentation writer to document a statement. Prior to VBA, such as WordBasic or QuickBasic types were given by appending a type character. EG `MyString$ = "Fred"`. – user18521918 Jun 15 '22 at 19:47
  • There are different forms of Hungarian Notation, here we are speaking about Systems Hungarian where the data type is used as a prefix in the variable naming. – user692942 Jun 17 '22 at 10:19
  • ... and in the system I am documenting, datatypes are being appended as suffixes to field names in a database. A sidebar about Hungarian will make a nice addition for junior developers. So the details are not as important as the convention's name and a link to an educational resource. – Jefferey Cave Jun 18 '22 at 14:10