Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Detailed Comments in NAV code

(0) ShareShare
ReportReport
Posted on by 60,161 Super User 2025 Season 1

I got a request to add comments like below for each line of code we modify or write

What are your thoughts with pros and cons?

IF (StartDate = 0D) AND (NOT UseEmploymentDate) THEN

  StartDate := WORKDATE;   // If Start Date is Null and the user did not check Use EmploymentDate then use the Workdate

 

IF (StartDate > EndDate) AND (EndDate <> 0D) THEN 

  ERROR(error2);    // If Start Date is After End Date and the End Date is not null then Error msg

*This post is locked for comments

  • Suggested answer
    Alexander Ermakov Profile Picture
    Alexander Ermakov 28,094 on at
    RE: Detailed Comments in NAV code

    Fully agree with Mouli kaku!

  • Suggested answer
    Amol Salvi Profile Picture
    Amol Salvi 18,694 on at
    RE: Detailed Comments in NAV code

    Even though CFMD also not required such a detail comments in code . If we write such comments in programming language then actual code will be hidden behind this comments. It will look like essay.

  • RE: Detailed Comments in NAV code

    There are no pros unless they are expecting non-developers to read the code

  • Suggested answer
    Mouli Kaku Profile Picture
    Mouli Kaku 515 on at
    RE: Detailed Comments in NAV code

    I recently Attended Master Classes by Mark Brummel, According to him remove Green Stuff as much as you can and encourage Natural Language Programming. So instead of comments I will create a Local Function

    replaceWorkDateIfnotUseEmployementDateandNull() 

    checkIfStartdateisgreaterthanEndDateandnotBlank()

    So when you go to codeunit and try to collapse you can read what is going on in the codeunit.

    Example

    https://github.com/markbrummel/Master-Class-Examples/blob/master/Exercise%203/COD60003.TXT

  • Suggested answer
    RobertasR Profile Picture
    RobertasR 5,002 on at
    RE: Detailed Comments in NAV code

    Hi Mohana

    It's a strange request as it might make the code harder to read with all the comments. Even so there is no point in writing a comment that tells you exactly what codes tells you anyway. I would rather put the reasoning - why is the part of the code run and what is achieved by that.

    Robertas

  • Rafael B. Profile Picture
    Rafael B. 715 on at
    RE: Detailed Comments in NAV code

    Hi @Mohana Yadav,

    I would say, too much info as text is long. All conditions are described in the code (IF statement). So, if end-users are not going to go into code to better understand what you did, I would reduce the text.

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans