touque.ca > Education Commons > Java > Resources > Comments

Simple Guide to Comments

  1. Place comments before the code they describe or explain.
  2. Never place comments at the end of a line of code.
  3. Your comments should provide a description of the algorithm to be followed, so “instruct” the computer using the imperative mood:
    • // Initialize the environment.
    • // Greet the user.
    • // Instruct the user.
    • // Gather valid data.
    • // Process data.
    • // Display results.
    • // Thank the user.
  4. Do not parrot the code. Assume your programmer-reader has a basic understanding of the language. For example, don’t do this:
    • // Assign the value y to a new variable called x.
    • int x = y;

touque.ca > Education Commons > Java > Resources > Comments

[This page last updated 2020-12-23 at 12h13 Toronto local time.]