Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualAzaral

Posted 17 April 2013 - 04:20 PM

EDIT:

By the way, I've never asked anyone this because I've rarely had anyone else read my code, but I wonder if this habit I have is a case of "overcommenting." Basically, I keep the opening brace on the same line, and I always comment the closing brace, even if it's really really obvious. It helps me with re-reading my code, but I do sometimes wonder if another programmer might think I'm overdoing it haha. For example:

void myFunction(){  if(/*condition*/){    doSomething(x, y);    doSomethingElse(a, b);    switch(/*condition*/){       case blah:           break;    }//end of switch  }//end of if}//end of myFunction()

I actually started doing that recently because it really helps clear up the end of a 4- or 5-level nested loop if you want to add to it later. After using lisp in college, I made a habit of always writing my opening and closing brace/parens IMMEDIATELY, and then adding the content inside. This leads to chains of closing braces at the end of some of my more workhorse functions or complex algorithms and it's really nice to have the tags via comments to see where you want to jump in to do something "inside loop 2 but post switch case".

Also, in general to the thread, I ALWAYS brace my conditionals, even if they're on one line. I've had too many stealth bugs creep in because I had skipped braces on a one-line if statement and added a second instruction.

 

I too automatically create the open and closed braces for bodies of code and then go back in and put the code in the body.

I don't think putting a comment at the end of braces is a bad idea at all, especially if you have a lot of nesting and things going on. Whatever helps you and others understand your code easier is not a waste of time in my opinion as long as you don't over do it.


#1Azaral

Posted 17 April 2013 - 04:20 PM

EDIT:

By the way, I've never asked anyone this because I've rarely had anyone else read my code, but I wonder if this habit I have is a case of "overcommenting." Basically, I keep the opening brace on the same line, and I always comment the closing brace, even if it's really really obvious. It helps me with re-reading my code, but I do sometimes wonder if another programmer might think I'm overdoing it haha. For example:

void myFunction(){  if(/*condition*/){    doSomething(x, y);    doSomethingElse(a, b);    switch(/*condition*/){       case blah:           break;    }//end of switch  }//end of if}//end of myFunction()

I actually started doing that recently because it really helps clear up the end of a 4- or 5-level nested loop if you want to add to it later. After using lisp in college, I made a habit of always writing my opening and closing brace/parens IMMEDIATELY, and then adding the content inside. This leads to chains of closing braces at the end of some of my more workhorse functions or complex algorithms and it's really nice to have the tags via comments to see where you want to jump in to do something "inside loop 2 but post switch case".

Also, in general to the thread, I ALWAYS brace my conditionals, even if they're on one line. I've had too many stealth bugs creep in because I had skipped braces on a one-line if statement and added a second instruction.

 

I to automatically create the open and closed braces for bodies of code and then go back in and put the code in the body.

I don't think putting a comment at the end of braces is a bad idea at all, especially if you have a lot of nesting and things going on. Whatever helps you and others understand your code easier is not a waste of time in my opinion as long as you don't over do it.


PARTNERS