Share via


X++ Standards: Constants

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

Follow the best practices rules about using constants. These are designed to make it easier to maintain X++ code.

Constants

Rule

Error level

Do not use hard-coded constants (except 0, 1, 100).

Warning

Define constants in a method, class declaration, or if necessary globally in a macro. Reuse existing constants.

Consider alternative ways of getting the constant:

None

User Interface Text

Rule

Error level

User interface text must be in double quotes, and you must always use a label (also in double quotes).

Error

User interface labels must be complete sentences. Do not build sentences using more than one label, or other constants or variables under program control (do not use concatenation).

Example:

Description description = "@SYS12345"

Use strFmt to format user interface text.

None

System-oriented Text

Rule

Error level

System-oriented text constants must be in single quotes.

None

Do not hard-code text.

Warning

Do not use labels. You will get a warning if a label is used inside single quotes.
Example:

#define.Filename('myFile.txt')
Filename filename = #Filename;

Warning

Numeric Constants

Rule

Error level

Always review the direct use of numeric constants, except for 0 meaning null, 1 meaning increment, and 100 when calculating percents and currencies.

None

Certain numeric constants are predefined, such as the number of days per week, and the number of hours per day. For example, see the TimeConstants and SysBitPos macros in the Application Object Tree (AOT).

None

See also

X++ Coding Standards

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.