Re: Design by Contract

From: Date: Tue, 10 Feb 2015 08:49:26 +0000
Subject: Re: Design by Contract
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  Groups: php.internals 
Request: Send a blank email to internals+get-82352@lists.php.net to get a copy of this message
I'm happy to clean up the RFC after Dmitry's changes are merged. Happy to author some of the content if Yasuo is busy or wants help ? Cheers Joe On Tue, Feb 10, 2015 at 8:29 AM, Dmitry Stogov <dmitry@zend.com> wrote: > A bit updated version of RFC is attached. > As I removed more than added, I decided not to put it on wiki before > internal agreement. > Actually, I would also remove most part of introduction as well, to make > RFC more compact and clean. > > I cnahged $> into $ret, because $> just won't work. Some better solution > is welcome. > > The RFC misses contract inheritance rules. They must be defined separately > for preconditions, postconditions and invariants. > Yasuo, could you please check, how it's implemented in D and add missing > section. > > We will need English correction after all. > > Thanks. Dmitry. > > On Tue, Feb 10, 2015 at 11:19 AM, Dmitry Stogov <dmitry@zend.com> wrote: > >> completely agree. contracts must be permanent. >> >> Thanks. Dmitry. >> >> On Tue, Feb 10, 2015 at 10:40 AM, Joe Watkins <pthreads@pthreads.org> >> wrote: >> >>> Example code never works, I can just say that's a bad abstraction, >>> vertebrate and invertebrate are distinct and abstraction should reflect >>> that. >>> >>> Why should we provide a way to change contracts is the question ? >>> >>> It doesn't seem to make sense to do that, a derived class should be able >>> to define additional contracts, but not change the contracts of it's parent. >>> >>> Cheers >>> Joe >>> >>> On Tue, Feb 10, 2015 at 7:36 AM, Yasuo Ohgaki <yohgaki@ohgaki.net> >>> wrote: >>> >>>> Hi Joe, >>>> >>>> On Tue, Feb 10, 2015 at 4:31 PM, Joe Watkins <pthreads@pthreads.org> >>>> wrote: >>>> >>>>> Actually I'm not sure it's at all sane to try to override contracts, >>>>> I'd actually avoid that completely, so no need to name contracts and no >>>>> need for magic __invariant. >>>> >>>> >>>> For example, >>>> >>>> class Animal { >>>> protected $legs; >>>> require($legs >= 0); >>>> } >>>> >>>> class Snake extends Animal { >>>> // Snake is fine, no leg >>>> } >>>> >>>> class Human extends Animal { >>>> // 2 legs. $this->leg === 2 >>>> } >>>> >>>> Overriding makes sense for many cases. >>>> >>>> Regards, >>>> >>>> -- >>>> Yasuo Ohgaki >>>> yohgaki@ohgaki.net >>>> >>> >>> >> >

« previous php.internals (#82352) next »