Have you even written some code then come back to it a few days or even months or years, and not understand what you were trying to do? This is a part of coding that few people actually practice yet alone try to master.
How should you comment your code? This depends on your style. I personally like to “box” everything in, so that the comments stand out. The issue that some people do not like about this type of commenting is that it makes the code seem longer. I personally think that it makes the code look cleaner.
When should you comment your code? Why should you comment your code? I comment my code before I actually have the code do something. If I am going to make a loop that will have it’s own comment box. If for some reason that I need to make a sudden change in the code or variable that will also get a comment. When making temporary variable, I comment those also.
You maybe saying to yourself, I wrote the code I will know what it does. Before using comments, I thought the same thing, but I can tell you that is not the case. After you deal with a code for a long time you think that you will never forget what each variable does, or how each function or style relates and why you created them. Remember that you will most likely work on other code, which may even use the same variables that you use in other code, which can cause confusion. It also helps if other people have to work with your code to know what you were thinking and why you where thinking it.
Below are some commenting styles you may want to try out and see which one you like the best.
Multiple Line Comments
Single Line Comments
Of course there are other styles of commenting this is just some of the common ones that programmers and designers use.