Monday, August 30, 2010

Epic Fail: JavaDoc

/**
 * This is a Java class. It contains one or more
 * methods that perform certain functions.
 */
class Foo {
  /**
   * A function that takes two parameters and
   * calculates the result depending on these
   * parameters.
   *
   * @param a The first parameter, a String.
   * @param b The second parameter, an integer.
   * @returns the result (as double), depending
   *   on the input parameters.
   * @throws Exception if an exception occurred.
   */
  public double calculateResult(String a, int b)
      throws Exception {
    return ((double) (a.length()*b)) / 3.4;
  }

  /**
   * This is an inner class that contains two
   * public variables.
   */
  class InnerClass {
    /**
     * A public String variable named x.
     */
    public String x;

    /**
     * A public string variable named y.
     */
    public String y;
  }
}

2 comments:

  1. Die klassische Art, ein Java-Programm zu dokumentieren. Idealerweise schreibt man ins JavaDoc natürlich hinein, was das Programm tut, statt das Offensichtliche zu wiederholen.

    Idealerweise würde der Kommentar bei der Funktion also eher in folgende Richtung gehen: "Calculates the result of concatenating b copies of the given String a and dividing the length of the resulting String by 3.4. @param a The String that should be copied and used for the calculation described above. Must not be null. @param b How often the String will be copied and concatenated. May be zero or negative. @returns the result of the calculation described above. @throws NullPointerException if null was given as String argument a."

    lG Birgit

    ReplyDelete