+ 3
Comment or not comment, that's the question
There are two big ways of thinking while coding and explicitly write a comment: people who comment well its code and people who doesn't comment. Who is right? And better, what do you usually do? Vote the comment that resumes you thinking way better. Edit: you can choose more than one option. Also, you can suggest more options to add to the list. Go on! 😃
10 ответов
+ 10
+ 9
comments are good they explain functionality of the code without needing to read the code in too much detail. going though thousand, million lines of code made few months ago, will you get the code easily without comments?
I believe good indentation and a little bit of comments (where needed like a complex function, etc) goes a long way. of course this depends on your use case for beginners maybe required to comment every two lines/statements for them to easily understand.
TL DR: comment where needed, indent your code properly. follow according to your needs.
+ 7
comments are very useful in coding.....
they help another person understand your code and at the same time then help you at the time of debugging or making changes to your code!!!
+ 4
If you need to put comment, most of the time it's because the code is not self-descriptive enough.
Comment is definitely helpful in some situation but if you find it often to comment and explain how the code works, you're in trouble.
Please leave it in the technical spec/documentation.
P/S: It doesn't not apply for beginners' code for future reference.
+ 4
The world isn't black and white only, there are mostly shade of grey rather than rarely full white and/or full black ^^
Depending of the purpose/people targeted to be reader of my codes, I write more or less comment... usually I'm very lazy, so I only add comments that try to make sense for me in future, but mostly when my code start to growing as much than I need to not handle all the stuff only in my mind: often too late, so I have learned to try to do it a few before that's required.
Anyway, writing code for explain/share purpose here have improved my effort to add more comments :)
Also, comments are relatively unuseful at time of writing, but becomes more important when debugging, and really usefull to dive again in old code, even if they are enough self-descriptive (we will re-read and re-understand it more efficiently ;P)... Also, comments can be confusing when there's too much of them (slicing the code, not let see block of codes at once, requiring more scrolling), but I tend to think that too much is better than not enough, and I frequently clean them of the less useful ones, trying to keep them in backups (as well as inserted debug lines, which I have habit to not indent them to easier find them and comment/uncomment them, as well as delete them when saving a cleaned state of my code)
+ 3
3. I usually write a line before a block of code with few words (less than 10, generally) that describes what the block (usually a function) does. I think this can help me and others to understand critical points of it, specially if the code is not intuitive or clear by itself.
+ 2
2. I write beautiful codes and correctly indented, there are not need of comments. More: if I write comments my code is more confusing with this gray lines. I really think my code can talk by itself with no extra support by writing human words.
+ 1
1. I try to comment line by line code to make it easy to understand by every user, also me, now and wherever I'll come to review it in the future
+ 1
4. I like to start the code with a excerpt of what it does, few lines in a multi-line comment, also my contact info, licensing, etc.
+ 1
5. I like to write comments after the line itself, not before. I think this mantain clear and with order the code, and if you need help to understand, this a notations are easy to follow. I think this is specially useful if you have a writer with no-wrapping option. It's a mix of the no comment option and the comment line by line one, but cleaner to read.