Static typing, Python, D, DbC

Lie Ryan lie.1296 at gmail.com
Sun Sep 12 08:00:24 EDT 2010


On 09/12/10 08:53, John Nagle wrote:
> On 9/11/2010 9:36 AM, Lie Ryan wrote:
>> On 09/12/10 00:33, Bearophile wrote:
>>
>>> ----------------
>>>
>>> Lately while I program with Python one of the D features that I most
>>> miss is a built-in Design By Contract (see PEP 316), because it avoids
>>> (or helps me to quickly find and fix) many bugs. In my opinion DbC is
>>> also very good used with doctests.
>>
>>> You may implement a poor's man DbC in Python like this:
>>
>> I would do it like this:
> 
>    Design by contract really isn't a good fit to Python.  I've
> done proof of correctness work, and there are suitable languages
> for it.  It needs a language where global static analysis is
> possible, so you can reliably tell what can changes what.

As long as you're not using some funny magic (e.g. monkey patching);
then IMO python copes reasonably well. Though, I agree, Python probably
isn't really suitable for formal proofing (the best way to assert
program's correctness in python is by unittesting, which isn't a formal
proof, just one that works most of the time).



More information about the Python-list mailing list