On Thu, Sep 9, 2021 at 12:38 PM Christopher Barker <pythonchb@gmail.com> wrote:
Take a look at the archives of this list -- there was a large conversation about DBC a while back (a year, two years ??? )

I think if you really want to support DBC, there will need to be more changes than this -- though there are libraries that support it with current Python.

Also, let's be clear about hte language re use -- when you say:

there should be lots of assertions, do you mean the english were assertion, or the Python keyword assert?

If the former, than you are free, or course, to use a ordinary if and raise to make all sort sof assertions about the code at runtime.

To me -- the entire point of the assert statement is that it is for testing, and can be turned off. If you want to check a condition always, just use an if and a raise:

How is this:

if value < 0:
    raise ValueError("this only works with positive numbers")

Any more difficult to read or write than:

assert value >= 0, raise ValueError("this only works with positive numbers")

-CHB

I have never heard of DBC and don't have a clue what is stands for. I am not a pro software developer.

But I would read these two lines differently, semantically. The if version feels like someone is saying "I am checking for a thing that could happen". The assert version would feel more like "maybe this could happen and I am checking for it because I am scared not to let's just put it here just in case", or said another way "it is imperative that this not happen".

Not sure if that is an argument for or against, and maybe I'm the only one who would see the semantics differently.


---
Ricky.

"I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler