[Python-ideas] Simplicity of C (was why is design-by-contracts not widely)

Steven D'Aprano steve at pearwood.info
Mon Oct 1 10:18:21 EDT 2018

On Sun, Sep 30, 2018 at 06:19:11PM -0400, Eric V. Smith wrote:
> On 9/30/2018 8:11 AM, Stephen J. Turnbull wrote:
> >Steven D'Aprano writes:
> >  > (7) You can't unit test loop invariants
> >
> >I don't see how a loop invariant can be elegantly specified without
> >mixing it in to the implementation.  Can you show an example of code
> >written in a language with support for loop invariants *not* mixed
> >into the implementation?
> I'd be very interested in this, too. Any pointers?

I'm not sure how Stephen went from my comment that you can't unit test 
loop invariants to the idea that loop invariants aren't in the 
implementation. Obviously the loop invariant has to be attached to the 
loop. You can't attach a loop invariant to a method or class, because 
they might contain more than one loop.


        x := 0
        x <= 10
        x > 10
        x := x + 1


More information about the Python-ideas mailing list