Since comments don't do anything for the code, what's the purpose of them? I know all languages have them, and sometimes when I view the source code of things I see them, but they don't really say anything useful. I think worrying about them is a waste of time.
Why are comments important?
Started by Sionofdarkness, Jul 22 2006 08:39 AM
10 replies to this topic
#1
Posted 22 July 2006 - 08:39 AM
|
|
|
#2
Posted 22 July 2006 - 02:26 PM
Comments are very important because if you look at your code a month after you create it you'll have no idea what you were doing and why you did it. With comments you don't have this problem. Also, comments are good if you are sharing work with another programmer.
#3
Posted 23 July 2006 - 06:17 AM
If the code is self-explanatory, there is no need for comments. Comments are useful for when you are doing something where either the algorithm or the technique is unclear. They are also useful in documenting specifications for functions or classes that someone else will be using. A common thing in programming is to have one person write a library for someone else, and only distribute the headers and compiled library. The person using the library can't see how things work, so must rely on the headers and comments to know what is legal and what isn't for that library.
#4
Posted 25 July 2006 - 05:09 AM
WingedPanther said:
If the code is self-explanatory, there is no need for comments. Comments are useful for when you are doing something where either the algorithm or the technique is unclear. They are also useful in documenting specifications for functions or classes that someone else will be using. A common thing in programming is to have one person write a library for someone else, and only distribute the headers and compiled library. The person using the library can't see how things work, so must rely on the headers and comments to know what is legal and what isn't for that library.
With that being said, the person using the library couldn't use it unless there were comments. A good programmer always uses comments.
for (int i;;) {
cout << "Smith";
}
#5
Posted 25 July 2006 - 09:02 AM
Alright, I understand. I'm sure it is especially important if you aren't the only person working on the code, because comments could also be used to tell your partner what to do.
#6
Posted 25 July 2006 - 02:32 PM
It's also useful when you pick up code after working on other things for 6 months. There's nothing like looking at code that you KNOW made perfect sense when you wrote it and scratching your head.
#7
Posted 25 July 2006 - 10:13 PM
Just a reminder: Comments aren't only for explaining the code (the how) but also for explaining why the code does what it does (the why).
If you're code isn't ridiculously complicated, it can be read and understood what it's doing...but without a comment, there's no way to know *why* it's doing it.
If you're code isn't ridiculously complicated, it can be read and understood what it's doing...but without a comment, there's no way to know *why* it's doing it.
#8
Posted 26 July 2006 - 04:23 PM
This is more of a topic for programming theory rather than language specific like Java.
food for thought.
food for thought.
#9
Guest_ShortCircuit_*
Posted 26 July 2006 - 05:32 PM
Guest_ShortCircuit_*
icepack is right. Comments are important in ALL coding, whether its HTML, Java, C++ etc - you should comment in everything you do.
#10
Posted 27 July 2006 - 02:12 PM
Well, I don't think they are very important in HTML as it is a very easy language to just look and see what is going on.
#11
Posted 29 July 2006 - 08:32 AM
I've coded in HTML a lot before and don't even know how to make comments there. In Java it's //, right (or \\ maybe), and I think in HTML it might be <!-- Hey --!> or something like that.


Sign In
Create Account


Back to top









