Table of Contents

RDC01002: Hungarian notation

Severity: Information  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: HungarianNotationAnalyzer

A name begins with a prefix that states its type.

strName and lngCount say in the name what the declaration says in its As clause, and go on saying it after the type changes. A name is reported when it begins with one of the lowercase prefixes below and what follows starts a new word, which an uppercase letter or a digit says: strName, sName and str1 are; stringent, index and str are not. The prefixes are those of Rubberduck's Hungarian notation inspection, and dic, rng, rs, wb and ws:

  • a type: a, arr, b, bln, by, byt, c, chr, col, cur, dat, dbl, dic, dt, dtm, i, int, l, lng, lst, n, o, obj, rng, rs, s, sng, str, udt, var, vnt, wb, ws;
  • a scope: g, m;
  • a module: bas, cls, frm;
  • a control or a database object: btn, cbo, chk, cmd, dao, dlg, drv, fld, fra, grd, idx, img, lbl, mnu, opt, pgr, pic, rpt, shp, tbd, tbl, tmr, txt.

The names it applies to are the ones the module chooses, like those of RDC01001. The diagnostic is an opinion of the analyzer and not a condition of the language. The names of the controls of a form (txtName, cmdOK) are not reported; a variable named like one is.

Approving a name

A name that begins like one and that is not - colWidth is a width, and not a collection - is approved by listing it, in the Configuration:Diagnostics section of the extension's appsettings.json. A name is compared without regard to case, and nothing is approved by default.

{
  "Configuration": {
    "Diagnostics": {
      "HungarianNotation": {
        "AllowedNames": [ "colWidth", "intervalStart" ]
      }
    }
  }
}

The list is DiagnosticsOptions.HungarianNotation. It is a suggestion because renaming does not change what the declaration is.

Fixing it

The diagnostic is fixed by renaming the declaration, which renames every name that refers to it (textDocument/rename). Its code actions are a rename to the word after the prefix (strName to Name), when that word is a name nothing else means where the declaration is used, and a rename to a name the user chooses.

How it is raised

Situation Example Resolution
A name chosen by the module begins with a prefix of its type, and is not approved. Dim strName As String Name what it is, and let the declaration say the type: Dim customerName As String; or approve it.
A name chosen by the module begins with a one-letter prefix, or a prefix and a digit. Dim sName As String, Dim mCount As Long, Dim str1 As String Name what it is, or approve it. str1 gets no suggested name, since no word follows its prefix.

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca