Ian Kelly <ian.g.ke...@gmail.com>: > On Wed, Nov 12, 2014 at 3:47 PM, Marko Rauhamaa <ma...@pacujo.net> wrote: >> Asserts have nothing to do with them being optimized out. Asserts are >> communication. >> >> Apart from idiomatic style, there is no difference between >> >> # never reached >> >> assert False >> >> raise RuntimeError('Unreachable code reached') > > If the purpose is communication, then the comment is most effective, > as it can easily convey anything you want. If the purpose is to detect > programming errors, then the RuntimeError is most effective, as it > will always raise an error in the event it is reached. > > assert False is a strange hybrid of the two that is less effective at > both purposes.
If assert weren't there, I would likely choose one of those two alternatives. But assert is there so there's no reason to avoid it. Marko -- https://mail.python.org/mailman/listinfo/python-list