And if you had not heard anything about "how to comment your code". So you were, you are or you will be confronted to THE question :
"What this code do ???"
And you know how it's painful when something doesn't work and you can't understand WHY !
When you use an external program, your reflex is to read documentation about this program to understand how to use this.
When you comment your code, the objectives is the same. You'll write some details for you in the future or for the people who use or improve this code.
The objectives is multiple, just think about you in 2 years in this code. You'll be happy to see somes comments who explain what is this weird classes you added before 😆.
Now, if you don't code alone. Think about you're associate will read and use your code.
And PLEASE, think about all people who use your code in the future if you're make an open source program.
I think you understand now, when you comment your code you actually :
- You saves time for you, and for other peoples
- Describe, and have a readable code
- Your code will be accessible
It's recommended to comment your class, you're function and use inline documentation when is necessary. I think it's the minimal requirement for a readable code.
A code has commented, is a readable code. BUT, use comment whith thriftiness.
Of course, if you're function is named
sumfor example, and take two arguments. It will be really simple to know what the function do.
Personaly I think you should comment for function when the function is over 10 lines, and it's required for classes.
And please remember, a developer does not only code.
A developer maintain, debug, keep an eye on evolution, document, and think how to resolve problems.
So please, comment your code and make happy the "you" of tomorrow and all people who read your code. And you'll make a step to become a programming god 😃.
Tell me if you have any suggestions, or remarks and of course if this article was interesting.
There is so much to say about this, feel free to express your point of view, so don't hesitate. 😜