detailed comments in NAV code

mohana_cse06
Member Posts: 5,506
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
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
-1
Comments
-
It's pointless to write in plain text what the code is supposed to do. IMHO comments are mostly bad. Even when not using code managing software I only mark my code with a start and end comment.
Exceptions are very rare, e. g. when the code is dependent on various setups and you have to know their values to understand what's supposed to happen in which case.0 -
Yes agreed, in the best situation, the comment the developer has added is correct.
If not, then it is worthless and will cause confusion.
The code should be written in a way it understandable without comments.
For instance in your example, you could move the code into functions like this...
UpdateStartDateIfNull(StartDate, UseEmploymentDate);
RaiseErrorIfStartDateGreaterThanEndDate(StartDate, EndDate);
1 -
imho writing a comment for every single code line, turns your objects into a huge tutorial. it'll not only took a lot of time, it'll also become a burden for developers. maybe it will be useful for juniors, but i don't think it's worth it.0
-
Dear all,
I believe this kind of requests comes from persons that are not developers although they want to fully understand the code.
In this case, that person has two solutions:- DO NOT READ THE CODE! Ask a developer kindly and he will answer all your questions
- Learn C/AL and then read the code.
Joking aside, I hardly believe that developers should use meaningful name for functions as suggested by @nick_robbo . This will be a lot helpfull than 100 lines of comments.0 - DO NOT READ THE CODE! Ask a developer kindly and he will answer all your questions
-
Hi,
I am all in favour of adding as comments between lines of code, but only sensible ones. I even tried in m company to port into NAV ground a good (imho) TSQL stored procedures writing habit- start the function or block of code by writing a short comment stating what the function is supposed to do, what it takes and what needs to be returned.
It makes no sense to add comments stating the obvious, or repeating almost exactly in plain words what the code is doing.
I am using myself a similar way of commenting in scenarios where the code is not self-documenting or obvious, but I am always trying to include in a reason why the particular code has been changed/added/removed. Maybe not on line-by-line basis, but often before a block of code.
I am also often using functions, often one-liners, just as a way of structuring and commenting my code, trying to clearly distinguish inputs and outputs. Also I am trying to name function after its hmm, higher level funcion (business purpose ?) Taking the @nick_robbo example:UpdateStartDateIfNull(StartDate, UseEmploymentDate);
I would rather write it like this:StartDate := GetProcessStartDate(StartDate, UseEmploymentDate);
I cannot see any cons to be fair - as long as the comments add some value - but I would not consider comments in your example as adding anything.
My 0.02£
Slawek
Slawek Guzek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-030
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions