Microsoft Dynamics AX 7 and the New X++

!
Warning: This post is over 365 days old. The information may be out of date.

The new Microsoft Dynamics AX also brings with it “the new X++”. Most of the changes received by the new X++ are related to the compiler and the tools to develop it. The compiler is completely new, making X++ another language in the .NET stack, which has allowed it to be fully integrated with Visual Studio and to avoid the two-part compilation of previous versions: No more p-code, all X++ code is now compiled directly to CIL. But we’ll talk about that another day, today we’re going to see the changes in the language itself, the syntax, available in the new version:

luke-skywalker

Improvements over AX 2012

  • Finally… added the finally block to try..catch structures. Its operation is the same as in C#, this block is executed whether or not errors occur in the try block.
  • You can initialize the value of class variables in the declaration itself.
  • Variables can be declared anywhere in the code, it’s no longer necessary to do all declarations at the beginning of methods, which allows declaring variables in a more specific scope (within loops, for example).
  • Added the special var type, which allows the compiler to infer the specific type of the variable. Its operation is the same as in C# but beware, in .NET this type is used to handle generic types, in X++ generic types are not yet available.
  • Added the using statement so we can use it just like in C#, that is:
    • To abbreviate references to complicated namespaces:
using System.Collections;

class ClaseEjemploXpp
{
    public static void main(Args args)
    {
        // It is not necessary to specify the complete type
        // System.Collections.Arraylist

        ArrayList arrayList = new ArrayList();
        arrayList.Add('Test');
    }
}

To create aliases for namespaces:

using SysCol = System.Collections;

class ClaseEjemploXpp
{
    public static void main(Args args)
    {
        SysCol.ArrayList arrayList = new SysCol.ArrayList();
        arrayList.Add('Test');
    }
}

To ensure proper use of types like IDisposable, for example (more information here):

using (Font font = new Font())
{
    // font.Method(...);
}

Is equivalent to:

Font font = new Font();
try
{
    // font.Methods(...);
}
finally
{
    font.Dispose();
}
  • Class variables can be static.
  • Classes can have a static constructor via the new typenew keyword. For example:
class ClassWithConstructor
{
    static str staticClassVariable = "Initialized";

    static void typenew()
    {
        staticClassVariable = "Assigned without this.";
    }
}
  • Attributes applied in classes and methods can omit the Attribute suffix in their name, just like in C#. For example, for an attribute called [PruebaAttribute] it will also be valid to use just [Prueba].
  • Delegates that before could only be declared in classes, can now also be declared in tables, forms and queries (Query objects).
  • The relationship between these delegates and the handler methods is now done through attributes.
  • Within forms, nested classes can be found within classes. The base class represents the form (an instance of FormRun) and the inner classes handle the form components (Controls, Data sources, etc.).

Backward Incompatibility

Although an effort has been made to minimize backward compatibility issues in the language, the platform change has inevitably led to removing parts of the language that manage aspects of the platform that no longer exist, such as the following:

  • Removed the following statements: changeSite, pause, windows. They cause compilation errors.
  • Since all code now runs in CIL on the server, the client and server statements no longer make sense. They don’t cause compilation errors but are ignored and should be removed.
  • In Microsoft Dynamics AX 2012 there were some differences in the execution of the same code in CIL or interpreting the p-code. In the new version all these cases work the same as in its previous CIL execution. For example:
    • The base type real is now a System.Decimal in all cases. The decimal precision has been modified from the real type of p-code. This difference often caused small decimal variations when code ran in CIL compared to its interpretation in p-code.
  • Direct assignment of an array to another array is done by reference. In p-code it was done by value.

Related Posts