On Sat, Sep 11, 2021 at 9:20 AM Juancarlo Añez <apalala@gmail.com> wrote:
I'm happy about dropping the DBC theme and rebooting to make assert easier to use so it gets used more.

I agree with Steven, Marc-Andé, and others in seeing "using assertions more" as an anti-goal.

This isn't to say that a given program should have fewer—nor more—lines that start with `assert`.  Rather, assertions should be use to ASSERT conditions that should NEVER be violated.  They are NOT to check whether user input is bad. Nor whether a disk is unreliable.  Nor whether a computation takes too long. Nor whether a value is outside of a useful range.  Nor any of the other things that regular exception handling is well designed for.

If for some reason you find yourself completely unable to write "if not (condition_to_check): ..." for mysterious reasons, you could use assert this way (but don't):

>>> try:
...     assert 2+2==5, "Bad arithmetic"
... except AssertionError:
...     print("Configuring stuff to log problem")
...     raise
...
Configuring stuff to log problem
Traceback (most recent call last):
  File "<ipython-input-3-2a9bdbc65744>", line 2, in <module>
    assert 2+2 == 5, "Bad arithmetic"
AssertionError: Bad arithmetic
 
But again, that's bad code for the same reason your proposal would be bad code.  Assertions have the entire purpose of being possible to disable, and to express conditions a programmer believes are *necessarily true*.


--
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons.  Intellectual property is
to the 21st century what the slave trade was to the 16th.