Comments |
Pre and post-conditions should be included in the comments for a method. The @return tag will normally include the postcondition in cases where the method returns a value. Preconditions for public methods should be checked at the beginning of a method, with an appropriate exception thrown if the precondition failed. Preconditions for private methods can be checked using an assert statement as their failure indicates an error by the programmer of the class, making it hard to recover from the error dynamically. Post-conditions are typically also checked via an assert statement, whether the method is public or private. If evaluating the assert statement is too expensive (e.g., essentially involves re-executing the method) then the assert statement may be omitted.
n = n + 1 // add one to n
Comments |