5 ms·
i dont understand why i as a user would want a program to assert (i.e. crash) in an interactive program. i would lose all my in-progress work and have to start
by doubloon 3y ago
i dont understand why i as a user would want a program to assert (i.e. crash) in an interactive program. i would lose all my in-progress work and have to start the program over from scratch. and chances are very low i will be able to report the bug to the programmer, for various reasons. so the programmer will never know about it. i will just keep having to restart the program over and over and workaround it.
i get that its better than memory corruption. but ... is it better than just muddling through and reporting you cannot do operation x?
- ok_dad 3y agoThis would probably be used in places where, if the “x” in assert(x) doesn’t hold, then the program could do more harm than good. You’ll generally try to handle situations that are recoverable without blowing up stuff like this, but in some software and some situations you want it to blow up fast rather than destroy data or whatever. I program in Python more, which has slightly different assert behavior so it’s considered more of a code smell in that language, but it seems like Java programmers use it more because it can be turned off easily when not wanted.
- flohofwoe 3y agoAsserts are not an alternative to validating user input or input data in general (e.g. data loaded from files or received over the network). If wrong input triggers an assert, that means that the input validation is incomplete (and in that case the assert may prevent further much worse damage, and also provide important information to the programmer who's going to fix that bug). Basically, asserts should never trigger if the user "does something wrong".
- thfuran 3y agoThe user obviously doesn't want the program to crash, but they don't want to encounter any bugs. If an assertion fails, it means they already encountered a bug and the program is about to wander through a minefield of unspecified behavior, which could be much worse than simply stopping.