Closed Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Why are comments important?

  1. #1
    Sionofdarkness is offline Programming Expert
    Join Date
    Jul 2006
    Posts
    383
    Rep Power
    0

    Why are comments important?

    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.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    dirkfirst is offline Programming Expert
    Join Date
    May 2006
    Posts
    354
    Rep Power
    23
    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.

  4. #3
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  5. #4
    smith is offline Programmer
    Join Date
    Jun 2006
    Posts
    153
    Rep Power
    0
    Quote Originally Posted by WingedPanther
    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.
    Code:
    for (int i;;) {
       cout << "Smith";
    }

  6. #5
    Sionofdarkness is offline Programming Expert
    Join Date
    Jul 2006
    Posts
    383
    Rep Power
    0
    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.

  7. #6
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143
    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.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  8. #7
    brackett is offline Programmer
    Join Date
    May 2006
    Posts
    192
    Rep Power
    22
    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.

  9. #8
    icepack's Avatar
    icepack is offline Programmer
    Join Date
    Jul 2006
    Location
    North Carolina
    Posts
    115
    Rep Power
    21
    This is more of a topic for programming theory rather than language specific like Java.


    food for thought.

  10. #9
    ShortCircuit Guest
    icepack is right. Comments are important in ALL coding, whether its HTML, Java, C++ etc - you should comment in everything you do.

  11. #10
    Crane's Avatar
    Crane is offline Programming Expert
    Join Date
    Nov 2005
    Posts
    398
    Rep Power
    25
    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.

Closed Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Comments
    By docmonkey in forum Database & Database Programming
    Replies: 2
    Last Post: 06-28-2011, 04:31 AM
  2. CSS comments?
    By Vswe in forum JavaScript and CSS
    Replies: 5
    Last Post: 11-04-2009, 01:37 PM
  3. IMPORTANT!!
    By Logan in forum The Lounge
    Replies: 29
    Last Post: 02-15-2009, 12:42 PM
  4. Comments?
    By dirkfirst in forum JavaScript and CSS
    Replies: 3
    Last Post: 01-19-2007, 07:29 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts