Gosu comments

Add comments to your Gosu code to explain its programming logic. Gosu supports several styles of comments.

Block comments

Use block comments to describe the purpose of classes and methods. A block comment begins with a slash/asterisk (/*) and ends with an asterisk/slash (*/).

  /*

  * This is a block comment.

  * Use block comments at the beginnings of files and before

  * classes and functions.

  */

Use proper capitalization and punctuation in block comments.

Single-line comments

Use single-line comments to describe one or more statements within a function or method. A single-line comment begins with double slashes (//) as the first non-whitespace characters on the line.

  if (condition) {

    // Handle the condition

    ...

    return true

  }

If you cannot fit your comment on a single line, use a sequence of single-line statements.

Trailing comments

Use trailing comments to briefly describe single lines of code. A trailing comment begins with double slashes (//) as the first non-whitespace characters after the code that the comment describes.

    if (a == 2) {

      return true  // Desired value of 'a'

    }

    else {

      return false // Unwanted value of 'a'

    }

If you place two or more trailing comments on lines of code in a block, indent them all to a common alignment

You can use some styles of comments to temporarily disable lines or blocks of code during development and testing. This technique is known as commenting out code.

Commenting out a single line of code

Use a single-line comment delimiter (//) to comment out a line of code.

  if (x = 3) {

    // y = z   This line is commented out for testing.

    y = z + 1  This line will excecute for testing.

  }

Commenting out a block of code

Use a pair of block comment delimiters (/*, */) to comment out a block of code, even if the block you want to comment out contains block comments.

/*

  /*

   * The function returns the sum of its parts.

   */

  public function myMethod(int A, int B) {

    return A + B

  }

*/

The preceding function cannot be called, because it is commented out. Gosu permits the nested block comment within the commented out block of code.

See also