Log in / create account | Login with OpenID
DocForge
An Open Wiki For Software Developers

Code comment

From DocForge

A code comment is text within source code which is useful for other programmers who are reading the code but generally ignored by the compiler or interpreter.

Example in PHP:

<?php
echo 'Hello';
// This comment will be ignored by the PHP interpreter
echo ', world!';
 
/*
  This comment will also be ignored, but is useful to humans.
 
  Output:
 
  Hello, world!
*/
?>

Some interpreters and runtime environments will take certain kinds of comments and make them available during runtime for reference. For example, Python:

>>> def commented_function:
...    """This comment within the function definition 
...    is available to the Python runtime environment. 
...    """
...    # It's called a docstring and can be found 
...    # in the __doc__ attribute. 
...    return 0
...
>>> commented_function.__doc__
'This comment within the function definition 
is available to the Python runtime environment.'