[osflash] Design By Contract on ActionScript 2

Martin Heidegger mastakaneda at gmail.com
Sun Oct 8 08:23:24 EDT 2006


To me working with interfaces is DBC. A object has a interface that allows
certain usage this usage is documented and tested with unit tests. is there
a need for more?

greetings
Martin.

2006/10/7, Bernd Will <bernd at ewill.de>:
>
>  Hello everybody,
>
>
>
> similar to doctest, DBC in Python is also easily injected by inserting
> inside those comment tags at the beginning of a method.
>
> It is very nice seeing UNITTEST and DBC in one comment placed directly
> below the method's head.
>
> Here an example for UNITTEST and DBC in Python:
>
>
>
> def sort(a):
>
>     """Sort a list *IN PLACE*.
>
>
>
>     >>> a = [1, 1, 1, 1, 1, 2, 2, 1]
>
>     >>> sort(a)
>
>     >>> a
>
>     [1, 1, 1, 1, 1, 1, 2, 2]
>
>     >>> a = 'the quick brown fox jumped over the lazy dog'.split()
>
>     >>> sort(a)
>
>     >>> a
>
>     ['brown', 'dog', 'fox', 'jumped', 'lazy', 'over', 'quick', 'the', 'the']
>
>
>
>     pre:
>
>         # must be a list
>
>         isinstance(a, list)
>
>
>
>         # all elements must be comparable with all other items
>
>         forall(range(len(a)),
>
>                lambda i: forall(range(len(a)),
>
>                                 lambda j: (a[i] < a[j]) ^ (a[i] >= a[j])))
>
>
>
>     post[a]:
>
>         # length of array is unchanged
>
>         len(a) == len(__old__.a)
>
>
>
>         # all elements given are still in the array
>
>         forall(__old__.a, lambda e: __old__.a.count(e) == a.count(e))
>
>
>
>         # the array is sorted
>
>         forall([a[i] >= a[i-1] for i in range(1, len(a))])
>
>     """
>
>     a.sort()
>
>
>
> # enable contract checking
>
> import contract
>
> contract.checkmod(__name__)
>
>
>
> def _test():
>
>     import doctest, sort
>
>     return doctest.testmod(sort)
>
>
>
> if __name__ == "__main__":
>
>     _test()
>
>
>
>
>
> Regards
>
> Bernd
>
>
>  ------------------------------
>
> *Von:* osflash-bounces at osflash.org [mailto:osflash-bounces at osflash.org] *Im
> Auftrag von *Miguel Serrano Milano
> *Gesendet:* Samstag, 7. Oktober 2006 16:09
> *An:* osflash at osflash.org
> *Betreff:* Re: [osflash] Design By Contract on ActionScript 2
>
>
>
>
>
>
>
> Hi! I've been thinking about this last days. There's no solution at the
> moment, but it is not difficult to develop a solution by one of this two
> ways:
>
>
>
> 1. Explicit asserts and an AOP approach to check and invariants. The
> asserts are easy to define: just a collection of Assert.precondition() and
> Assert.precondition(), and as invariants a method classInvariants() could
> be defined to be invoked after every method call.
>
>
>
> 2. A precompiler. I think there are tools to write precompilers for any
> language. Do somebody know something about this?
>
>
>
> What do you think?
>
>
>
>
>
>
>
>  Message: 1
>
> Date: Thu, 5 Oct 2006 15:11:13 -0300
>
> From: "Marcelo de Moraes Serpa" <celoserpa at gmail.com>
>
> Subject: [osflash] Design By Contract on ActionScript 2
>
> To: osflash at osflash.org
>
> Message-ID:
>
>             <1e5bcefd0610051111u32390762kc43f423a31d8b4f5 at mail.gmail.com>
>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>
>
> Is there any tool for AS2 that allows me to implement the DBC methodology?
>
>
>
> Cheers,
>
>
>
> Marceo.
>
>
>
> Miguel Serrano Milano
>
> mserranom at gmail.com
>
>
>
>
>
>
>
> _______________________________________________
> osflash mailing list
> osflash at osflash.org
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
>
>


-- 
ICQ: 117662935
Skype: mastakaneda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://osflash.org/pipermail/osflash_osflash.org/attachments/20061008/139c866a/attachment.htm


More information about the osflash mailing list