You might want to read up on Design By Contract, if you haven't already. It's an approach to writing robust software by incorporating explicit pre- and post-conditions into code. IIRC they were used to generate documentation for functions as well as to do the run-time checks. It originally came from the Eiffel community I believe, but has spread to other languages as well.