Thursday, September 20, 2012

Max AX method name and best practices

The maximum length for an AX method in AX is 40 characters.

If the name is too long you'll get the compilation error 'Name is too long. Truncate name to '[>40 character method name here]'.

Remember when you name your AX classes, the names should start with the three letter prefix [e.g. abc], then the module it belongs to [e.g. Sales], then the functionality that it follows where appropriately, ending with a brief description of the purpose. The ultimate goal is to be able to see the class name and know exactly what the class extends and if its custom and what it does.

The methods within this class then should be able to not only follow the base overrides (find, exist, modifiedField, etc), but also provide a directed purpose where appropriate. It is good to keep in mind the best practices behind a method when determining the name of the methods.

A refresher around the functions of AX methods best practices. There are a lot more than the below (like keeping variables as local as possible) but these are general.

MSDN: Best Practices for Methods [AX 2012]
Methods should:
  • Be logical.
  • Do a specific task.
  • Have no side effects.
  • Be well structured, especially when it comes to good places for overriding and for overlayering.
Make your methods small and logical. If you have a method that does more than one 'thing'; then consider splitting it up in two (or more) methods. It will then be easier to override or overlayer exactly the functionality that needs to be specialized or customized.
Do not have any unused variables in your methods.

No comments:

Post a Comment