What you wrote is prerequisites and an important element in Design by Contract . Google (or "StackOverflow" :) for this period, and you will find quite a lot of good information about it, as well as some bad information. Note that the method also includes postconditions and the concept of a class invariant .
Keep clear that statements are a valid mechanism.
Of course, they usually ( not always ) are not checked in release mode, so this means that you need to check your code before releasing it.
If statements are left included and the statement is violated, standard behavior in some languages that use statements (in particular, in the Eiffel) is an exception to the exclusion of the statement.
Statements that have not been noted are not a convenient or appropriate mechanism if you publish a library of codes, as well as a (obviously) way to verify direct, possibly incorrect, input. If you have “possibly incorrect input”, you need to develop an input validation level as part of your program’s normal behavior; but you can still freely use assertions in internal modules.
Other languages, such as Java, have a more tradition of explicitly checking arguments and throwing exceptions if they are mistaken , mainly because these languages do not have a strong “statement” or “design” by contract.
(This may seem strange to some, but I find the differences in tradition respectable and not necessarily evil).
See also this related question .
source share