Answer the question
In order to leave comments, you need to log in
Is it considered professional to comment on blocks and code sets in this way?
Good afternoon, I'm a beginner and therefore I'm not sure if it's professional to use so many comments in the code, as I actually do? I always try to separate each section separately and write a lot of explanations.
For example, this is the full name of the file at the beginning of localization.js:
// ##################################################################### //
// ############### Localization/Lokalisierung/Локализация ############## //
// ##################################################################### //
//================================================================================
// LocalStorage Support
// Lokale Speicherung
// Поддержка локального хранения данных
//================================================================================
if ('localStorage' in window) {
var usrLang = localStorage.getItem('uiLang');
if (usrLang) {
lang = usrLang
}
}
$(document).ready(function () {
$(".lang").each(function (index, element) {
$(this).text(arrLang[lang][$(this).attr("key")]);
});
});
$(document).ready(function () {
//Здесь используем css класс lang
$(".lang").each(function (index, element) {
$(this).text(arrLang[lang][$(this).attr("key")]);
});
});
Answer the question
In order to leave comments, you need to log in
There is a standard https://jsdoc.app/
here with examples
https://ru.wikipedia.org/wiki/JSDoc
https://devdocs.magento.com/guides/v2.3/coding-sta...
https ://devhints.io/jsdoc
If you stick to the standard, then you can not only see them with your eyes, you can also generate documentation from them, and IDEs like the storm will be able to automatically take into account what you have written in the comments.
The taste and color ...
I believe that comments should carry a semantic load and explanation, and not look beautiful
// ################################################ ##################### // //
// ############### Localization/Lokalisierung/Localization ##### ######### //
// ##################################### ################################# //
1. No, not right. The comment should say not how the code works, but what it is supposed to do .
That this code " Here we use the css class lang " can be seen from the code and so. But the comment does not answer the question, why does he do it? Apparently this is the implementation of localization. Then that's how it should be written.
I support the answers above.
“Good code does not need comments” comes to mind, but they are needed either where there is tricky logic, or as a prerequisite for linters.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question