Results 1 to 7 of 7
  1. #1
    xhoneyskye is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default So when it says to comment your code..?

    Am I supposed to comment every single line explaining what it does? Major portion of my code repeats the same thing over and over again.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by xhoneyskye View Post
    Am I supposed to comment every single line explaining what it does?
    No, most definitely not. Your goal should be to write code that is "self-commenting" where the variable and method names are so logical that they almost make it obvious what is going on. You should comment most methods, especially public ones, anything that may be confusing, and anything that your instructor says should be commented.
    Major portion of my code repeats the same thing over and over again.
    That sounds like code that should be refactored then. You might want to place the repeating bits into a method and then use loops as needed.
    Last edited by Fubarable; 01-27-2010 at 03:57 AM.

  3. #3
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default

    What Fubarable is on point, but if actual commenting

    Java Code:
    //comment goes here
    is needed, then I'd suggest block commenting.. At the head of every code which is similar, have a comment saying what the function of that block of code does.

  4. #4
    xhoneyskye is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by Fubarable View Post
    No, most definitely not. Your goal should be to write code that is "self-commenting" where the variable and method names are so logical that they almost make it obvious what is going on. You should comment most methods, especially public ones, anything that may be confusing, and anything that your instructor says should be commented.

    That sounds like code that should be refactored then. You might want to place the repeating bits into a method and then use loops as needed.
    Thanks. Informative, but I still refuse to use loops. I suck at it. Majorly.

    :)

  5. #5
    xhoneyskye is offline Member
    Join Date
    Jan 2010
    Posts
    5
    Rep Power
    0

    Default

    Quote Originally Posted by ecliptical View Post
    What Fubarable is on point, but if actual commenting

    Java Code:
    //comment goes here
    is needed, then I'd suggest block commenting.. At the head of every code which is similar, have a comment saying what the function of that block of code does.
    Oh, okay. That makes sense, thank you.

  6. #6
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    if it may help
    Java Code:
    //comment 1
    non-javadoc comments
    Java Code:
    /*
    */
    javadoc comments
    Java Code:
    /**
    */

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,967
    Rep Power
    19

    Default

    I have a tendency to comment as part of the design (which goes back to the days when I had to do sequence diagrams). So a key method would look something like this before I even added any code to it:
    Java Code:
    public void processSomething() {
        // First get the data.
        // loop over it.
            // call the thing.
            // call the other thing.
        // finally send data somewhere else.
    }
    The advantage (in my mind) is that you can see to turn each of those comments (bar the loop) into a call to another method, thus breakig up the work done by a single method, and you've also commented your thought processes which led you to write this in the way you have. I'm a firm believer on writing comments based on the fact the reader is going to be a bit thick...even that reader is going to be you in a few weeks time.

Similar Threads

  1. How to generate comment or javadoc in java file ?
    By Tonny in forum Advanced Java
    Replies: 2
    Last Post: 01-03-2010, 05:49 PM
  2. How to strip out comment tags
    By mr.vinnie in forum New To Java
    Replies: 3
    Last Post: 09-30-2009, 02:12 AM
  3. URL/comment problem
    By Chasingxsuns in forum New To Java
    Replies: 4
    Last Post: 07-25-2009, 03:10 AM
  4. About Comment By Using SAX
    By tapas in forum XML
    Replies: 1
    Last Post: 01-24-2008, 05:29 AM

Posting Permissions

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