Skip to content

Hungarian notation #30

Open
Open
@spartanatreyu

Description

@spartanatreyu

Hungrian notation should be added to the list of notations in the docs/lexicon page.

Hungarian notation resembles "camelCase" and "PascalCase" with the exception that it has a prefix that denotes some additional semantic meaning (usually data type). For example:

  • pContractor is a pointer that points to a Contractor object.
  • bEmployed is a boolean representing whether someone is employed or not.
  • fHourlyPayRate is a float representing the amount a contractor is paid per hour.

Hungarian notation can be extended to include the scope that the variable exists within. For example:

  • m_iDaysWorked represents the number of days someone has worked for, that is stored as an integer and whose value is a member (meaning: is independent for each instance) of a class, in this case of contractor.
  • s_iNumberOfOpenContractorPositions represents the total number of contractor positions available, stored as an integer. Since this value would be the same for all instances of the contractor class, it is declared and assigned statically on the contractor class itself.

More info: https://en.wikipedia.org/wiki/Hungarian_notation.

Personal note: While hungarian notation is falling out of use thanks to more modern development environments and tooling, it is still prevelent in many older and/or larger projects. It is also worth being aware about to prevent confusion among developers from different backgrounds. For instance:

Programmer A creates a variable called iHaveCompletedCourse, and commits the code to a project. Some time later, Programmer B tries to use or updates the variable iHaveCompletedCourse and ends up encountering errors. Now they have to spend time trying to determine why a variable they think is an integer, is not accepting an integer value when in fact it was a boolean and the "i" is in fact refering to whether the user themselves have completed a course or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions