Re: Python experiences: Duck Vs Design by Contract was Re: Fruit basket program in Boo,Other Script Langs

  • From: Veli-Pekka Tätilä <vtatila@xxxxxxxxxxxxxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 22 Oct 2007 21:51:18 +0300

Hi James,
I think he means you can test correctness conditions in the code and
optionally only include those tests in debug builds. Much like the
assert macroes in C. Design by contract is about classes that are able
to define and check method pre and post conditions for their objects, as
well as invariant conditions that must hold true for the lifetime of the
object. For Perl, for instance, there's the die operator, flags telling
if the debugger is on, and modules like Class::Contract for design by
contract programming.

Is the design by contract really built into Python or is it a clever
add-on module? Isn't the whole duck typing, and if there's a method
named like that we hope it will work, philosophy against design by
contract? I kinda like duck typing in Perl, Ruby or whatever, but still.
Java's interfaces do force you to define an exact API.

With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:

james.homme@xxxxxxxxxxxx wrote:
> Hi Richard,
> What does this mean in english?
> One more thing in the advantage column:
> Python, like many other languages, supports assertions.  I am a strong
> advocate of the "Programming as contract" concept as introduced by Bertrand
> Meyer in the late 1980's in the Eiffel language.  Python supports that
> notion, which can help ensure program correctness.
> Richard
View the list's information and change your settings at 

Other related posts: