Why should I write comments in my code?

Question

Is there a reason to comment code? If I’m writing it, I’m familiar with what it’s doing.

Answer

Writing helpful comments in your programs is an excellent habit! You may understand what you’re writing in the moment, but if you look at that same code six months from now, it may not be so clear, especially as your projects grow in size!

It’s a good idea to briefly explain your code anywhere you think it might help your future self, or other programmers who may read your code.

7 Likes

what will happen to the code when its progressing ?

2 Likes

The computer ignores comments, so there’s no performance reason not to use them.

4 Likes

there is one thing i like to know. in my company there is a rule to not explain code in comments. So there usually are no information about it and it is hard to follow up. For me as trainee it is often hard to undertand a complex piece of code.

Is this a usual company approach?

3 Likes

Yes. Useless comments create clutter and make code less readable.

In the professional environment, the goal is to write code that is easy to understand and to read. Comments are usually reserved for referencing issues, documentation of functions and to describe the code that for some reason had to be written in a complicated manner.

If there is in fact complex piece of code which is hard to understand - git blame, find out who wrote this piece and tell this person that they did a bad job.

9 Likes

thx,
this was exactly the thing. everyone was complaining about the code that was written from people before and that was not easy to understand exspecially for trainees.

So i think it is good to find a compromise between the use of comments and clean coding. but if every programmer of a company uses another style to code their should be some guidelines about this.

1 Like