Reply to comment

Comment Styles for C-Style Code

If there's anything that annoys people more than funky indentation, it's bad comments. I don't mean about the code, but in the code.


function name()
{
/* Once upon a time, all my comments
were inside the functions.
*/
}

It seemed to makse sense, but there's something that sucks about having to scroll more to start reading code.

/* Moving it up above the function seems to help!
So i did this for a while.
*/
function name()
{
...codehere....
{

Lately, all the languages are getting automatic documentation generation. They use comments like this:

/**
* The code comments here get turned into web pages.
* I like how there's a little extra whitespace above and below.
* And the stars are a pain to keep adding, even with editor support.
*/
function name()
{
...codehere...
}

But these docs look like really decent docs. In Perl:

#
# This function does nothing at all.
#
sub name
{
...codehere...
}

Again, there's all that extra whitespace. It gives the eyes a break.

As you can see, the main trends here are to move the comments out of the function, and to add more visual cues in the comments.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul> <p> <br> <div> <pre> <code> <img><h1><h2><h3><h4> <blockquote>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

.