Commenting standard

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

There is no “standard” except that you should make code that other can understand. Comments may help with it. If you feel that your code doesn’t look good, you’re probably not doing it right. But I can’t comment on your code, because I don’t know it.

Hi Martin,

Thanks for your reply. Can you please help me to the following example?

Example 1:

tablebuffer1.id = 1;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

tablebuffer1.id = 2;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

tablebuffer1.id = 3;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

Example 2:

if(condition1)

{

statements

}

In the example 1, i just want to use the loop to avoid the code repeation

In the example 2, i just want to add another condition (condition2)

Thanks,

Hari

I’m lost. It seems that now you’re asking about how to use loops in X++, but I thought this thread was about comments. Can you explain me once more what your question is about?

Hi Martin,

I have added comments in the below code. Can you please guide me that it is ok?

// Apr 30, 2015 - Hari - Use loop to avoid code repeating - starts

for(i=1; i<=3; i++)

{

tablebuffer1.id = i;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

}

// Apr 30, 2015 - Hari - Use loop to avoid code repeating - ends

// Apr 30, 2015 - Hari - Use loop to avoid code repeating - starts

/*

tablebuffer1.id = 1;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

tablebuffer1.id = 2;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

tablebuffer1.id = 3;

tablebuffer1.name = tablebuffer2.name;

tablebuffer1.description = tablebuffer2.description;

tablebuffer1.insert();

*/

// Apr 30, 2015 - Hari - Use loop to avoid code repeating - ends

Example 2:

if(condition1 && condition2) // Apr 30, 2015 - Hari - Added condition2

{

statements

}

Thanks,

Hari

I don’t see any value in keeping commented-out code in place. It’s just a clutter making your code less readable and increasing maintenance cost.

I would delete it completely. If anybody is interested in the previous version (which is unlikely), he can find it in version control.

Regarding “adding condition” - it doesn’t add any value for understanding the code; again, it’s just clutter. If you want to know who and when changed the code, look into version control. Annotate in TFS is a great tool for this purpose.

Most teams use some kind of comments when adding custom code into Microsoft’s code but there is no need to have details such as date.

Super.

Thanks,

Hari