Braces

[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 recommendations for using braces in Microsoft code name “M” code.

Do Place Braces on Their Own Lines for Type, Extent, and Computed Value Definitions

The following “M” code example shows the correct way to use braces within type, extent, and computed value definitions.

type Person
{
    Id : Integer32;  

    FullName : Text;

} where identity Id;

Addresses : 
{
    City : Text;

    State : Text;

    PostalCode : Text;

}*;

Avoid using braces on lines with other code as in the following “M” code example.

type Person {
    Id : Integer32;  

    FullName : Text; } where identity Id;

Addresses : {
    City : Text;

    State : Text;

    PostalCode : Text; }*;

Do Place Braces on Their Own Lines for Lists that Require Multiple Lines

If a list requires more than one line, place the braces on their own lines. It is acceptable to place braces and their contents on the same line when they enclose short lists of values that fit on one line. The following “M” code example initializes entities that fit on one line.

ContactType : Text where value in {"Friend","Family","Business"};

    People
    {
        {FirstName = "Mary", LastName = "Smith", Age = 27},
        {FirstName = "Joe", LastName = "Brown", Age = 29}
    };

The following “M” code example shows an incorrect way of initializing a People extent when each entity requires multiple lines.

module Contact
{
    People
    {
        MarySmith {FirstName = "Mary", LastName = "Smith", MiddleInitial = "E",
        Age = 27, ContactType = "Friend"},
        JoeBrown {FirstName = "Joe", LastName = "Brown", MiddleInitial = "B",
        Age = 29, ContactType = "Friend"}
    };
}

In the preceding example, the braces around each named entity should be place on their own lines. Each initialized field should also be placed on its own line within the braces.

Note

Note that you should always place braces on their own lines when declaring types, extents, or computed values. This is true even when those definitions are short and could fit on one line.

Do Align Opening and Closing Braces

Align the opening and closing braces of the same code block for braces that are isolated on different lines. The following “M” code example follows this guideline.

type Person
{
    Id : Integer32;

    FirstName : Text;

    LastName : Text;

} where identity Id;

The following “M” code example is incorrect, because the opening brace is not aligned with the closing brace.

type Person {
    Id : Integer32;

    FirstName : Text;

    LastName : Text;

} where identity Id;

See Also

Other Resources

"M" Coding Conventions