Yeah but it’s better to use them in debugging, I would prefer if statements.
personally I use asserts to debug, but if I’ve gotten it functioning fully how I want it, including what I want and need, I just have a few if not X then return end
making sure I have all the required fields, so rather than erroring, and possibly breaking stuff further down the line, it can continue seamlessly.
I also personally tend towards if
statements more than assert
s, since I try to have my code take as few dependencies as possible, and the ability to create stuff on the fly if it’s not been passed, which can’t be done using assert
, since it halts the thread
For things that you assert, you want them to error and break. The whole point of asserts is if for any reason they fail, you have a bug. You don’t use asserts for stuff like user input