Juancarlo A$(D+P(Bez writes: > assert cond: > # Write some debugging info to a log. > ... > raise ExtType(args) > > I like the idea of preparing the arguments for the assertion message in a > context that gets executed only when the assertion fails.
The more I see this elaborated, the less I like it. "assert" has a traditional meaning in programming, which is only a slight extension on the English meaning (that you can turn the check off for performance). Although the idea that assert could be the fundamental building block for design-by-contract (DBC), to my mind this has three problems. (1) You're coopting a keyword that has a consistent established meaning in English, in programming languages in general, and in Python, and changing that meaning. (2) I doubt that "assert" alone is sufficient for DBC. In practice, you'll want a more expressive, larger vocabulary. It's not clear that *any* of that vocabulary is best expressed by "assert" at this point. If not, why mess with what works? (3) There's a subtle difference between an assertion and a contract. An assertion is a statement of fact: it's either right or it's wrong. But the whole point of contracts in the real world is that they are constraints on behavior to be enforced. The assumption is that it's possible to be in violation of the contract. The point of *asserting* something is that you believe it's absolutely true, there's no point in going on if it's false. You have to start over. A presumption that violation is possible may not be true of the contracts in DBC, I don't know. But I would prefer not to mix the difficulties of the semantics of "contract" with the simplicity of the semantics of "assert". Steve _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/G5MX4OBWUUJKQKHSCN3OCZBG7C6KP2G2/ Code of Conduct: http://python.org/psf/codeofconduct/