Code Compiler
Whenever you make a
change to X++ code, you must recompile, just as you would in any other
development language. You start the recompile by pressing F7 in the X++
code editor. Your code also recompiles whenever you close the editor or
save a dirty element.
The compiler also produces a list of the following information:
Compiler errors These prevent code from compiling and should be fixed as soon as possible.
Compiler warnings These typically indicate that something is wrong in the implementation. See Table 1,
later in this section, for a list of compiler warnings. Compiler
warnings can and should be addressed. Check-in attempts with compiler
warnings are rejected.
Table 1. Compiler Warnings
Warning Message | Level |
---|
Break statement found outside legal context | 1 |
The new method of a derived class does not call super() | 1 |
The new method of a derived class may not call super() | 1 |
Function never returns a value | 1 |
Not all paths return a value | 1 |
Assignment/comparison loses precision | 1 |
Unreachable code | 2 |
Empty compound statement | 3 |
Class names should start with an uppercase letter | 4 |
Member names should start with a lowercase letter | 4 |
Tasks (also known as to-dos)
The compiler picks up single-line comments that start with TODO. These
comments can be useful during development for adding reminders, but you
should use them only in cases in which implementation can’t be
completed.
For
example, you might use a to-do comment when you’re waiting for a
check-in from another developer. You should avoid using to-do comments
just to postpone work. For a developer, there is nothing worse than
debugging an issue at a customer site and finding a to-do comment
indicating that the issue was already known but overlooked.
Note
Unlike
other languages, X++ requires that you compile only code you’ve
modified. This is because the intermediate language the compiler
produces is persisted along with the X++ code and metadata. Of course,
your changes can require other methods consuming your code to be changed
and recompiled if, for example, you rename a method or modify its
parameters. If the consumers are not recompiled, a run-time error is
thrown when they are invoked. This means that you can execute your
business application even when compile errors exist, as long as you
don’t use the code that can’t compile. You should always compile the
entire AOT when you consider your changes complete, and you should fix
any compilation errors found. |
The Compiler Output dialog box provides access to everything reported during compilation, as shown in Figure 1.
Each category of findings has a dedicated tab: Status, Errors And
Warnings, Best Practices, and Tasks. Each tab contains the same
information for each issue that the compiler detects—a description of
the issue and its location. For example, the Status tab shows a count of
the detected issues.
You can export compile
results. This capability is useful if you want to share the list of
issues with team members. The exported file is an HTML file that can be
viewed in Microsoft Internet Explorer or re-imported into the Compiler
Output dialog box in another Dynamics AX session.
In the Compiler
Output dialog box, click Setup and then click Compiler to define the
types of issues that the compiler should report. Compiler warnings are
grouped into four levels, as shown in Table 1.
Dynamics AX SDK
Constructing
quality software has become a daunting task in the 21st century. Many
new competencies are expected of the developer, and mastering them fully
and at all times is nearly impossible. Today you must write code
conforming to many technical requirements, including security,
localization, internationalization, customization, performance,
accessibility, reliability, scalability, compatibility, supportability,
interoperability, and so on. The list seems to grow with each software
revision, and keeping up with all of these competencies is increasingly
difficult.
Microsoft Dynamics AX
2009 includes a software development kit (SDK) that explains how to
satisfy these requirements when you use MorphX. You can access the SDK
from the application Help menu under Developer Help. We highly recommend
that you read the Developer Help section—it’s not just for novices but
also for experienced developers, who will find that the content has been
extensively revised for Dynamics AX 2009. The SDK is frequently
refreshed with new content, so you might want to check it often on MSDN.
Among other critical
information, the Developer Help section of the SDK includes an important
discussion on conforming to best practices in Dynamics AX. The
motivation for conforming to best practices should be obvious to anyone.
Constructing code that follows proven standards and patterns can’t
guarantee a project’s success, but it certainly minimizes the risk of
failure. To ensure your project’s success, you should learn, conform to,
and advocate best practices within your group.
The following are a few benefits of following best practices:
You avoid
less-than-obvious pitfalls. Following best practices helps you avoid
many obstacles, even those that surface only in border scenarios that
would otherwise be difficult and time consuming to detect and test.
Using best practices allows you to leverage the combined experiences of
Dynamics AX expert developers.
The
learning curve is flattened. When you perform similar tasks in a
standard way, you are more comfortable in an unknown area of the
application. Consequently, adding new resources to a project is more
cost efficient, and downstream consumers of the code are able to make
changes more readily.
You
are making a long-term investment. Code that conforms to standards is
less likely to require rework during an upgrade process, whether you’re
upgrading to Dynamics AX 2009, installing service packs, or upgrading to
future releases.
You
are more likely to ship on time. Most of the problems you face when
implementing a solution in Dynamics AX have been solved at least once
before. Choosing a proven solution results in faster implementation and
less regression. You can find solutions to known problems in both the
Developer Help section of the SDK and the code base.