Comments: From pattern to anti-pattern back and forth
The beginning: comments are mandatory!!
I am an old-school boy, and I began in the development world with Cobol and Structured Programming. These days the mainstream was to write a lot of comments. End, enough, next.
Here comes Uncle Bob: comments are forbidden!!
Here came the OOP and Uncle Bob published “Clean Code” principles. We became craftsmen and then comments were forbidden. Why? Because we are craftsmen and our code must be so expressive and our nomenclature so good that comments are indicative of lack of good design and redundant.
Seriously, I Agree. If you and your organization are working in a standardized way, comments only must have a place: when you assume a design decision hard to explain in another way to your fellows (or yourself four weeks ago). A logical step IMO.
Commentator 3: Rise of the machines
The comments (almost) disappeared from the world I was happy with that. But then came my new best friend, Git-Copilot. I was developing lots of features in JavaScript to convert all our C/SIDE code in the new AL, with extensions that could increase my speed conversion.
Working with AL with Git Co-Pilot is a disaster, but if you need other languages as JavaScript is a real pair programming. And works this way:
.You write a comment explaining in natural language what you want to code.
.It suggests the code and if you agree you confirm this code with tab key.
You tab and get:
I didn't delete the comment lines and in some extensions I have lots of comments again. And this part of the story is all speculation, but I feel that Co-pilot needs comments in our repos to learn programming. Is a fact it learns from existing repos, therefore somebody soon would tell us to place more comments in the code to let Co-pilot learn from it. Conclusion: machine learning could bring us back comments in programming.
Extra bonus: The with statement
I got the pleasure to assist Gary Winter sessions from 2014 to 2015. He introduced lots of Clean Code concepts in NAV world. One of these concepts was the use of With instruction to ease code readability. I agreed (again). The with provide us more readability avoiding the object repetition in all the lines:
But some years later, in AL language, using “with” we get this message in problems panel:
"message": "The 'with' statement is deprecated and will be removed for cloud development in a future release. This warning will become an error in a future release."
Again from pattern to smell. The reason? I will speculate again. The automatic tools are not very comfortable with implicit stuff. Now, I am creating VSCode tools, I find it more difficult to extract symbols info if we are working inside a “With” block. But I am not sure. If someone reads this and has any ideas, please comment.

Like
Report
*This post is locked for comments