Results 1 to 3 of 3
  1. #1
    Googol is offline Member
    Join Date
    Aug 2012
    Posts
    11
    Rep Power
    0

    Default Comment Location

    Which do you think? I have been swapping between these two styles for some time now and just can't seem to decide.

    PHP Code:
    /*
     * Comment before line: seems to be easier to mentally process the information.
     * 
     */
        // list already contains item so...
        if (list.contains(item))
            System.out.println("Present");
        
    /*
     * Comment after line: the code looks much more organized when the comment is in this location. Opinion I know but 
     * perhaps others agree.
     */
        if (list.contains(item))
            // list already contains item so...
            System.out.println("Present");

  2. #2
    Ronin is offline Senior Member
    Join Date
    Oct 2010
    Posts
    335
    Rep Power
    4

    Default Re: Comment Location

    Hi Googol,

    This is more down to personal preference. As long as the intention of both the comment and code is understood then it really doesn't matter.
    Java Code:
    if (list.contains(item)) // list already contains item so...
            System.out.println("Present");
    The above is also acceptable.
    One thing I cannot stand is the overuse of comments. Things like:
    Java Code:
    if (list.contains(item)) //checks if list contains item.
            System.out.println("Present"); //prints out "Present".
    else // if list doesn't contain item
            System.out.println("Not present"); // prints out "Not present".

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default Re: Comment Location

    What I hate even more is incorrect comment:

    Java Code:
    int i= 1; // initialize i to zero
    int j= i-1; //  j starts equal to i
    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 03:53 PM
  2. So when it says to comment your code..?
    By xhoneyskye in forum New To Java
    Replies: 6
    Last Post: 01-27-2010, 09:26 AM
  3. location provider returns no location
    By sandeeprao.techno in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-24-2009, 09:54 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
  •