Home   :   Matrix Language   :   Coding Style

Coding Style Rules

 

Matrix has a built in coding style which has the favourable effect of ensuring all Matrix models look the same in terms of how things are laid out and organised.

 

Models are organised by statements.  Each Matrix statement defines a region (or scope) under which all further statements are indented.  A subregion is similar to a region except that a subregion does not include the statement itself.

 

Alignment is very important in the Matrix Language.  Statements and their subregions are always indented by four spaces.  Anything else is an error.

 

The data items defined in subregions under Object statements must be always be aligned, although this is not checked for at present.

 

Everything in Matrix is case sensitive.  The use of the tab character anywhere is forbidden as is any white space or non printing characters except for space.

 

Spaces are required between names and the colon character.  Space characters are widely used as a delimiter.

 

Names may only contain alpha characters and underscores.  They must not start or end with an underscore and must not contain two consecutive underscores such as "__".  No digits are allowed.

 

Matrix has no reserved words due to its rigid format.  Names of all the Matrix modeling formalism entities have their own namespaces due to declaration and name format rules.

 

The text format is specified for statements and names.  Several examples are given below:

Camel Case:

Statement Names:

CreationState

Directive Names:

Zero

Capped Case:

Type Names:

Account_Number

Entity Names:

Bank_Policy

State Names:

In_Good_Standing

Dataset Names:

Customer_Name

Identifier Names:

Dog_Name

Sentence Case:

Attribute Names:

Maximum_velocity

Relationship Names:

Owned_by

Event Names:

Withdrawal_submitted

State Data Names:

Amount

Upper Case:

Enumeration Literal Names:

TUESDAY

Object Identity Literal Names:

ID001

Lower Case:

Process Data Names:

sub_total

Blank lines are allowed as they assist to visually break up the code, but no matter where they occur they are ignored completely.  No text is allowed after any statement.  Trailing spaces are identified and signalled as errors in all cases.

 

The "|" character indicates the start of a remark (comment) line.

 

There exists no blanket multi-line comment statement in Matrix such as /* ... */ found in C. This means every line can be considered part of a live statement if it does not begin with a "|" character.  If Matrix code is searched and only a single line is found and displayed, it can be easily determined whether that code is a comment line or not.

 

Only one statement per line is allowed and they may not be split over multiple lines.

 

During compilation, Matrix fully analyses all aspects of the model.  If an error is found, compilation stops immediately and it is reported to the analyst.  No attempt to continue is made and there may be many errors still remaining.

 

This is a deliberate attempt to encourage the analyst to get it right first time by fully understanding what the code does and not relying on the Model Compiler to catch errors.

 

The Matrix Model Compiler does not issue warnings, only errors.  Matrix code is considered completely correct or simply wrong.

Copyright 2017 Dark Matter Systems Ltd. All Rights Reserved.