Quantus icon indicating copy to clipboard operation
Quantus copied to clipboard

raise exceptions instead of asserting conditions

Open dkrako opened this issue 3 years ago • 0 comments

This is just a minor issue most of the time, but using assertions for checking input variables can lead to problems for people using this package.

The problem is, that assertions are deactivated when you use the optimization parameter -O on launching python. So as an example if a user wants to optimize the interpreter/compiler for memory-efficiency, all of the assertions in this package will be ignored. Most people don't use this optimization parameter, but I think we should be aware of this issue and maybe even enforce this for newly written code.

Here are some discussions on stackoverflow which can be helpful: https://stackoverflow.com/questions/944592/best-practice-for-using-assert https://stackoverflow.com/questions/28608385/assert-asserting-when-debug-false https://stackoverflow.com/questions/56990925/is-this-assert-for-development-not-for-production

TLDR:

  • use exceptions for the user-side of the package, where things can go wrong by unintended input/output
  • use assertions for the developer-side of the package, to assert conditions that should absolutely never go wrong, independent of user input

dkrako avatar Mar 16 '22 12:03 dkrako