D
D
Danny132020-06-03 11:47:04
Web development
Danny13, 2020-06-03 11:47:04

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/Локализация ############## //
// ##################################################################### //


This is for the local data save function:
//================================================================================
// 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")]);
    });
});


For small clarifications right in the code

$(document).ready(function () {
//Здесь используем css класс lang
    $(".lang").each(function (index, element) {
        $(this).text(arrLang[lang][$(this).attr("key")]);
    });
});


1. Is it right to do this?
2. With each comment, I increase the file size - is this a trifle that you do not need to pay attention to, an important need, or just the wrong behavior of the developer?

Thank you!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
Stalker_RED, 2020-06-03
@Danny13

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.

N
noob noob, 2020-06-03
@YashaWeb

The taste and color ...
I believe that comments should carry a semantic load and explanation, and not look beautiful

// ################################################ ##################### // //
// ############### Localization/Lokalisierung/Localization ##### ######### //
// ##################################### ################################# //

I don’t see any point in this, you can read the file name anyway

A
Alexey Sundukov, 2020-06-03
@alekciy

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.

A
Anton Litvinenko, 2020-06-03
@AntonLitvinenko

For javascript there is jsdoc

E
Egor Ommonik, 2020-06-03
@Ommonick

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 question

Ask a Question

731 491 924 answers to any question