The best practice principles for writing X + + advocated by MS Dynamics Ax are still very useful for reference. So review and understand the new and borrowed to remember.
General coding principles for Microsoft Dynamics AX.
- Declare variables as locally as possible.
- Check the error conditions in the beginning; Return/abort as early as possible.
- There are only one successful return point in the code (typically, the last statement), with the exception of switch cases, or When checking for start conditions.
- Keep the building Blocks (methods) small and clear. A method should do a, well-defined job. It should therefore is easy to name a method.
- Put braces around every block of statements, even if there is only one statement in the block.
- Put comments in your code, telling others "what's the code is supposed to do, and" What's the parameters for.
- Do not assign values to, or manipulate, actual parameters that is "supplied" by value. You should all able to trust, the value of such a parameter is the one initially supplied. Treat such parameters as constants.
- Clean up your code; Delete unused variables, methods and classes.
- Never let the user experience a runtime error. Take appropriate actions to either manage the situation programmatically or throw a error informing the user in the I Nfolog about the problem and what actions can is taken to fix the problem.
- Never make assignments to the ' this ' variable.
- Avoid dead Code. Reuse code. Avoid using the same lines of code in numerous places. Consider moving them to a method instead.
- Never use Infolog.add directly. Use the indirection methods:error, warning, info and checkfailed.
- Design your application to avoid deadlocks.
Happy cnblogging:)
x + + Coding standards [MSDN AX 2012]