web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Commenting standards

(0) ShareShare
ReportReport
Posted on by 3

Hi All,

Can you please share the commenting standard?

I can follow the commenting if i added one or tow lines in the code.

Sometime, i have to change the most of the existing code.
For example:
1. Using the loop concept to avoid repeating code run.
2. Add new contion in the existing if statement

After completed the changes, i can feel that i have added lot of comments. Finally, the code not looks good.

Thanks,
Hari

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    299,704 Super User 2025 Season 2 on at
    RE: Commenting standards

    Hi Hari,

    Many developers like to put comments in code where they changed something. Note that also comparing layers will provide the changes. In a situation where you have to modify one object for multiple requirements, comment are useful.

    When you have to rewrite a lot of standard coding, you can disable a larger group of lines and have a copy with the new coding below this. Then it look like this:

    // Start - ...
    /*
      ... old code
      ... old code
    */
       ... new code
       ... new code
    // End - ...

  • Suggested answer
    Sohaib Cheema Profile Picture
    49,022 User Group Leader on at
    RE: Commenting standards

    Microsoft has specified very shortly about comments

    msdn.microsoft.com/.../aa855488.aspx

    How your code looks like, is in your own hands as editor is not much rich, if you will compare it with Visual Studio.

    There are editor extensions developed on codeplex, which may help you a bit

    ax2012editorext.codeplex.com

    apart from that you can use comments as Microsoft has used at most of places

    e.g.

    //<Customized; Author:  ; ReasonCode:  ; Peroject:  ; Details>

    your code here

    //</Customized; Author:  ; ReasonCode:  ; Peroject:  ; Details>

  • Suggested answer
    syed baber Profile Picture
    11,633 on at
    RE: Commenting standards

    Hi Hariharan,

    We usually use the following format for commenting the modifications:

    // SharedProject name, Developer Name, Modification date - Begin

    X++ code modifications

    // SharedProject name, Developer Name, Modification date - End

    Also, I modified the EditorScripts class and added a method inside this class to automate this process somehow. If anyone wants to add code comment, he just need to select the code, right click and select the option from the menu (Scripts -> Tagging -> CodeModifications) which opens a dialog asking for project name and then clicking OK button on that dialog will add the tagging as per your coding standards. Below is the code:

    // This method will add the Start and end tags

    public void tagging_CodeModifications(Editor editor)

    {

       #Define.NextLine('\n')

       int currentLineNo = editor.selectionStartLine();

       int currentCol = editor.selectionStartCol();

       int selectedLine = editor.selectionEndLine();

       Dialog          dialog          = new Dialog("Enter Project Name");

       DialogField     dlgExtTypeName  = dialog.addField(extendedTypeStr(Name));

       container       dialogValue;

       str tab = "";

       tab = strRep("\t", currentCol/4);

       dialogValue = xSysLastValue::getValue(curExt(), curUserId(), UtilElementType::ClassInstanceMethod, "SaveLastValue");

       if (dialogValue != conNull())

       {

           dlgExtTypeName.value(conPeek(dialogValue, 1));

       }

       if (dialog.run())

       {

           dialogValue = conNull();

           dialogValue += dlgExtTypeName.value();

           xSysLastValue::putValue(dialogValue, curExt(), curUserId(), UtilElementType::ClassInstanceMethod, "SaveLastValue");

           editor.gotoLine(currentLineNo - 1);

           editor.gotoLine(currentLineNo);

           editor.gotoCol(currentCol);

           editor.insertLines(strFmt('// YourProjectPrefix_%1 %2 %3 Begin %4 %5', dlgExtTypeName.value(), strReplace(curUserId(),"I_",""), systemDateGet(), #NextLine, tab));

           editor.gotoLine(selectedLine + 2);

           editor.insertLines(strFmt('%1// YourProjectPrefix_%2 %3 %4 End %5', tab, dlgExtTypeName.value(), strReplace(curUserId(),"I_",""), systemDateGet(), #NextLine));

       }

    }

    Please let me know if you have further queries.

    Thanks,

    Baber.

  • Suggested answer
    raelhefn Profile Picture
    on at
    RE: Commenting standards

    Comments in X++ like C++ and C#

    Line comments

    // your comments

    block comments

    /*

      your comments

    */

  • Verified answer
    Iulian Cordobin Profile Picture
    8,201 on at
    RE: Commenting standards

    I think your talking about changing existing code, in which case two rules could apply:

    a) if it's standard code, you can enclose it with multiline comments /* */ and then just add your code with just one or two lines of description. This will also made easy upgrading later the code.

    b) if it's custom code, you can just replace it (remove the old code and add the new one). Again just a short description of the new code, but keep in mind the comments have to be concise, a long comment will not make it necessarily easy for another person to understand the implementation.

  • Verified answer
    Martin Dráb Profile Picture
    236,751 Most Valuable Professional on at
    RE: Commenting standards

    If interested, see my answers in DUG forum. I didn't noticed that this is another thread duplicated to both forums.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
AlissonGodoy Profile Picture

AlissonGodoy 2

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans