Share via


Naming

[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]

The following guidelines provide naming conventions for “M” code.

Do Use Pascal Casing

Use Pascal casing for module, type, extent, computed value, and field names. The following “M” code shows the use of Pascal casing.

type Person 
{
    HomeAddress : Address?;
    ...
}

type FullTimeEmployee {...}

The following “M” code example incorrectly uses lower Camel casing.

type person
{
    homeAddress : Address?;
    ...
}

type fullTimeEmployee {...}

Do Use Singular Nouns for Type Names that Represent Things

Types that represent either abstract or concrete things or concepts should be named with singular nouns or gerunds, nouns formed from a verb. These names should be based on the name of the thing they represent. Plural nouns should be used only for concepts that are sets rather than singletons.

type Customer {...}

type Assignment {...}

In the preceding example, it would be incorrect to use the plural type names Customers or Assignments.

Consider Using an Adjective for Types that Apply Qualities to Other Types or Extents

Some types define common fields or constraints that are meant to be applied to other types and extents. In these situations, consider using an adjective or adjectival phrase for these types. The following “M” code provides examples of possible types in this category.

type Quantifiable {...}

type Composable {...}

type HasName {...}

type GovernedByPolicy {...}

Do Use Plural Nouns for Extent Names

Using a plural noun serves as a clue that the construct is an extent rather than a type. The name of an extent is also used in the generated SQL as the table name; using a plural name conforms to standard SQL naming practices. If an extent is based on one or more types, name the extent with the plural form of the primary type name. The following “M” code shows several examples of plural extent names.

People : Person*; 

Customers : Customer*;

Assignments : Assignment*;

Consider Using a Noun Formed from a Verb for Types and Extents that Express Relationships

When you create a type or extent that represents a relationship between other types and extents, consider using a noun or noun phrase that reflects the key verb in the relationship. Use a single form for the type and a plural form for the extent. The following “M” code is an example of this guideline.

type Person {...} 

type Project {...}

type Assignment
{
    AssignedPerson : Person;

    AssignedToProject : Project;

}

Assignments : Assignment*;

In the preceding example, there are two types, Person and Project (the definition of these types is not shown here). The Assignment type expresses a relationship between a person and the project that they are assigned to. The type name Assignment is a noun that is based on the key verb in this relationship, “assign”. A Person is assigned to a Project. The Assignements extent uses the plural form of the type name, because it provides storage for a collection of Assignment instances.

Consider Naming Reference Fields with a Relationship Role Name

Consider naming fields and computed values to emphasize the relationship that they represent. Use a relationship role name or a phrase that describes the role of the referenced type in the relationship. Use a singular name for fields that reference a single instance. This is particularly valuable when a type definition contains multiple fields that reference the same type. The following two “M” examples show examples of this naming convention.

type Person 
{
    Supervisor : Person?;

    Mentor : Person?;
    ...
} 

type ProjectAssignment
{
    AssignedPerson : Person;

    AssignedToProject : Project;

    AssignmentFromDate : DateTime;
 
    AssignmentToDate : DateTime?;
    ...
}

In the preceding example, the Person type has two fields, Supervisor and Mentor. These two types are also references to the same Person type. The overall definition of the Person type is more easily understood by using role names for these two Person fields.

The preceding example also defines a ProjectAssignment type. This type uses two noun phrases, AssignedPerson and AssignedToProject. These phrases describe the relationship of the referenced types, Person and Project.

Do Not Use Fully Qualified Names unless Necessary

It is unnecessary to use fully qualified names in “M” code unless necessary to disambiguate the name from other similar names. An example of a fully qualified name would be Contact.People where Contact is the module name and People is the extent name. Unless an imported module also contains an extent named People, it is unnecessary to use the fully qualified name for the extent.

See Also

Other Resources

"M" Coding Conventions