Important facts to remember about assertions

  • Avoid using assertion in public methods
  • Assertions are meant for development environment only, avoid using them for production environment.
  • Assertions are best suits for the purpose of debugging while developemnt
  • Assertions are best practice to use them for
    • private methods
    • default case of a switch.
  • assert statement can save to get rid of writing if/else conditions
  • Assertion increases the readability
  • Don’t ever use assertions if your going to recover from something, it should be exception.
  • Even if you execute your program 1000 times assert statements should impact behavior of your program. i.e. assetion should side effect the program behavior.
  • By default assertions are disabled.
  • Assertions for meant for developers or development time only, if you want to show exception or problem feedback message to end user ,then assertion are not right choice, you should use exceptions.
HTML Comment Box is loading comments...