can any one explain the meaning of the statement “assertions let you test your assumptions during development but assertion code basically evaporates when the program is deployed leaving behind no overhead or debugging code to track down and remove”
Share
EDIT: asserts should be used to detect coding errors rather than input errors.
They allow you to document the assumptions made in coding in a way which can be enforced when assertions are turned on. However these checks are ones which a well tested program shouldn’t need on once released.
They are not suitable for validating user input as they are not designed to be friendly and assume the only way to fix a failed assertion is to fix the code (often killing or disabling the program in the process)
For validating user input, an
if(!condition) friendly_user_message()is a better approach.assertions allow you to perform expensive tests you want to be able to turn off for production cocde.
The JVM optimises out the assertions when you don’t have them turned on.
EDIT: You may have a complex check you want to perform if asserts are on. Two ways you can do this are.
OR