General Naming Conventions

Word Choices

  • DO choose easily readable, descriptive names. A property named HorizontalAlignment is more English-readable than AlignmentHorizontal.

  • DO favour readability over brevity. The property name CanScrollHorizontally is better than ScrollableX.

  • ✅ Boolean identifier should be named with affirmative form.

    Both “Is” and “Can” are OK (and so is “Has”) as a prefix for a Boolean.

    • In plain English, “Is” would be used to identify something about the type itself, not what it can do. For example, IsFixed, IsDerivedFrom, IsNullable can all be found in CLR types and methods.

      In all of these cases, “Is” is followed by an adjective.

    • Meanwhile, “can” more clearly indicates a capability. E.g. CanEdit, CanRead, CanSeek. In each of these cases, can is followed by a verb.

  • AVOID short names or names that can be mistaken for other names.

    bool b001 = lo == l0 ? I1 == 11 : lOl != 101;
    
  • AVOID including numbers in variables, parameters and type members.

    In most cases they are a lazy excuse for not defining a clear and intention-revealing name.

  • DO NOT use underscores, hyphens, or any other non-alphanumeric characters.

    Exception: you can prefix private fields with an underscore.

    // Correct
    public DateTime clientAppointment;
    public TimeSpan timeLeft;
    
    // Avoid
    public DateTime client_Appointment;
    public TimeSpan time_Left;
    
    // Exception (Class field)
    private DateTime _registrationDate;
    
  • DO NOT use Hungarian notation.

Cost should be cost not dCost (where the d would indicate that its decimal).
  • DO NOT use reserved language keywords as names.

    int, string, List are some examples of reserved keywords.
    
  • DO NOT repeat the name of a class or enumeration in its members.

    public class Employee
    {
        // Avoid
        public void UpdateEmployee(Employee employee)
        {
        }
    
        public void InsertEmployee(Employee employee)
        {
        }
    
        // Correct
        public void Update(Employee employee)
        {
        }
    
        public void Insert(Employee employee)
        {
        }
    
        // Also correct
        public void AddNewJob()
        {
        }
    
        public void RegisterForMeeting()
        {
        }
    }
    

    In above example you are talking about employee then there should no action method name with Employee prefix or extension

Abbreviations and Acronyms

  • DO NOT use abbreviations and/or acronyms as part of identifier names.

Exceptions: abbreviations commonly used as names, such as Id, Xml, Ftp, Uri.

// Correct
UserGroup userGroup;
Assignment employeeAssignment;

// Avoid
UserGroup usrGrp;
Assignment empAssignment;

// Exceptions
CustomerId customerId;
XmlDocument xmlDocument;
FtpHelper ftpHelper;
UriPart uriPart;

Avoid Language Specific Names

  • ✅ DO name members, parameters and variables according to their meaning and not their type.
    • Use functional names. For example, GetLength is a better name than GetInt.
    • Don’t use terms like Enum, Class or Struct in a name.
    • Name collection identifiers with a plural phrase describing the items in the collection instead of using a singular phrase followed by “List” or “Collection.”
    • Don’t include the type in variable names, except to avoid clashes with other variables.

Learn More