[Python-ideas] hookable assertions - to support testing utilities and debugging

Nick Coghlan ncoghlan at gmail.com
Thu Feb 19 12:32:26 CET 2015


On 19 February 2015 at 21:16, Ronny Pfannschmidt
<opensource at ronnypfannschmidt.de> wrote:
>
> Im aware, my intent is to standardize the mechanism and push it into the
> language,

Unfortunately, you're faced with a lot of C programmers firmly of the
opinion that if you care about whether or not a piece of code gets
executed, you don't put it it in an assert statement. It's a giant
flashing red sign that says "This code is just checking something that
should always be true, you don't actually need to read it in order to
understand what this code is doing, but the assumption it documents
may be helpful if something is puzzling you".

So from my perspective (being one of the aforementioned C
programmers), I see this question as not so much about the assert
statement per se, but rather a more philosophical question:

* is testing code categorically different from production code?
* if yes, should assert statements be handled differently in testing code?
* if yes, how should that difference be communicated to readers and to
the interpreter?

(FWIW, I'm personally inclined to answer the first two questions with
"yes", but haven't got any ideas as far as the third one goes)

Making the behaviour of assert statements configurable attempts to
duck those questions instead of answering them, so I don't see at as a
particularly useful approach - it makes the language more complex
without providing additional clarity, rather than figuring out how to
encode a genuinely important categorical distinction between test code
and production code into the design of the language.

Regards,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list