I
I
IvanIF2021-05-18 00:11:58
Programming
IvanIF, 2021-05-18 00:11:58

How to stop commenting on everything?

When I first started coding (~2 years ago), I didn't comment at all. Working files with code were written very quickly, one might say they were stamped. But it was impossible to understand them without half a liter, because no one will read 500 lines of solid characters on a sober head... The matter was further complicated by the fact that I learned programming on my own, so I did not know the generally accepted standards and principles of good manners in code.

When it came to some changes in the code, I had to read that same 500-line treatise for a long time. Of course, I quickly realized that such code was not worth writing and began to add spaces and comments.

Gradually, my code evolved into something more or less pleasing to the eye. There were still few comments, and many of the few were out of place, but the code definitely got better.

So I gradually added comments until I hit the other extreme - there were too many comments. I am at this extreme now. At some point, I began to catch myself thinking that 20% of the time I write code, and the remaining 80% I think about and write comments. It even goes to the following extremes:

// Переменная для хранения информации о возможности клика по кнопке «Зарегистрироваться»
// true — клик разрешён, false — клик запрещён
var can_click_su = true;

It’s as if an obsessive thought has settled in my head, which says: “Comment it out, then you won’t understand!”.
How to deal with it???

Answer the question

In order to leave comments, you need to log in

8 answer(s)
A
Alexey Yarkov, 2021-05-18
@IvanIF

Write code that is self-documenting.
Give meaningful names to variables and functions, albeit longer, but more readable.
Read about architecture, patterns.
I recommend "Clean Code" by R. Martin. There this topic comes up.

C
cicatrix, 2021-05-18
@cicatrix

Do not be afraid of long names of variables and methods, if the code explains itself, then comments are not needed.
If I do it for myself, I made it a rule to explain to myself in the future what is happening here in principle.
I also comment on non-trivial solutions. Moreover, in this case it is very detailed, sometimes with http links to the description of this or that algorithm.
In general, if you follow these principles and you get a lot of comments, then this is a sure sign that the method or even the whole class needs to be rewritten again.

D
Denis Fedorets, 2021-05-18
@fedorez

familiar. I also once scribbled green screens on VB6 somehow
... you need to take it and stop commenting on everything.
When I switched to languages ​​that allowed long variable names, now I'm Writing Awesome Long Variables That I Understand.
in fact, in this case, with normal meaningful names of variables, functions, classes, only a very small part of the code requires commenting - when you need to explain why it is so here (often, by the way, this is a sign of a crutch)

S
Saboteur, 2021-05-18
@saboteur_kiev

// Variable for storing information about the possibility of clicking on the "Register" button
// true — click is allowed, false — click is prohibited
var can_click_su = true;

Change to
var can_click_register_button = true;

F
Foxbator, 2021-05-21
@Foxbator

var registration_button_enable = true;

V
Vladislav, 2021-05-22
@Wyrd

Something tells me that your problem is not technical, rather it looks like some kind of obsessive desire to “explain everything” (you write about it yourself). Try to find a psychotherapist. Just do not confuse with a psychiatrist - a psychiatrist treats diseases (with pills), and a psychotherapist helps to understand the reasons for his desires / actions, to begin to relate to what is happening in life differently, etc. - quite healthy people who want to change something in themselves go to them. I'm not kidding - my wife is a psychotherapist.

M
mkone112, 2021-05-23
@mkone112

Break the slash out of the keyboard.

L
Lev Zabudkin, 2021-06-08
@zabudkin

In fact, this is a philosophical question, but I would recommend drinking a course of vitamins, especially B and drinking Nootropil with Glycine.
Month 3.
And then everything will return to normal.
The latter is especially useful for study and mental stress, but when there are not enough B vitamins, there is an ache in the bones.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question