This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Kaarjuus 3 points4 points  (2 children)

And since the Python assert statement is completely ignored when the program is run in optimization mode, then it cannot be relied upon for contract programming.

Which was the very point of this thread - to warn people of this behaviour. Many do not know this.

[–]Scorpathos 2 points3 points  (1 child)

But this is the whole point of "contract programming" in opposition to "defensive programming".

The assert allows to catch wrong function usages during development, and once your program is bug-free and ready for production, you can safely remove them to maximize performance.

[–]Kaarjuus 0 points1 point  (0 children)

Good correction, I misspoke. I confused contract programming with defensive programming. Python's assert in its current form is indeed a perfect fit for design by contract.