Why using Introduce Assertion?

Syahriga Syahrul 2 years ago updated by anonymous 2 years ago 1

Hi there, i think it's clear in subject, since the assertion are using for test development, and not in production state. why using it just to remove comment? what is your consideration on using it?


Hi Syahriga!

Thanks for asking. Let me answer your questions by simply quoting parts of the article for starters:

> Why using it just to remove comment?

Make these assumptions obvious by adding corresponding assertions. As with type hinting in method parameters, these assertions can act as live documentation for your code.

> What is your consideration on using it?

If the exception can be caused by actions of the user or system and you can handle the exception. On the other hand, ordinary unnamed and unhandled exceptions are basically equivalent to simple assertions – you don’t handle them and they’re caused exclusively as the result of a program bug that never should have occurred.

If you have a followup question, shoot it! I'd be happy to help.