17.2. Development guidelines

  1. Fail fast. There are several levels of fail fast, from better to worse:
    1. Fail Fast at compile time. For example: Don't accept an Object as parameter if it needs to be a String or an Integer.
    2. Fail Fast at startup time. For example: if the configuration parameter needs to be a positive int and it's negative, fail fast
    3. Fail Fast at runtime. For example: if the request needs to contain a double between 0.0 and 1.0 and it's bigger than 1.0, fail fast.
    4. Fail Fast at runtime in assertion mode if the detection performance cost is high. For example: If, after every low level iteration, the variable A needs to be equal to the square root of B, check it if and only if an assert flag is set to true (usually controlled by the EnvironmentMode).
  2. Exception messages
    1. The Exception message must include the name and state of each relevant variable. For example:
      if (fooSize < 0) {
          throw new IllegalArgumentException("The fooSize (" + fooSize + ") of bar (" + this + ") must be positive.");
      }
      Notice that the output clearly explains what's wrong:
      Exception in thread "main" java.lang.IllegalArgumentException: The fooSize (-5) must be positive.
          at ...
    2. Whenever possible, the Exception message must include context.
    3. Whenever the fix is not obvious, the Exception message must include advice.
      Exception in thread "main" java.lang.IllegalArgumentException: UndoMove corruption: ...
        1) Check your custom createUndoMove() of ...
        2) Check your custom Variable listeners if ...
          at ...