Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98505 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 36026 invoked from network); 12 Mar 2017 10:43:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 12 Mar 2017 10:43:30 -0000 Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.85 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.85 mx104.easyname.com Received: from [77.244.243.85] ([77.244.243.85:59674] helo=mx104.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 70/2B-38004-05625C85 for ; Sun, 12 Mar 2017 05:43:28 -0500 Received: from cable-81-173-135-7.netcologne.de ([81.173.135.7] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1cn0yA-0001hs-Mk; Sun, 12 Mar 2017 10:43:25 +0000 Reply-To: internals@lists.php.net References: To: Yasuo Ohgaki , Michael Vostrikov Cc: PHP Internals Message-ID: <2a928258-af19-c15f-548f-eb348b3f5449@fleshgrinder.com> Date: Sun, 12 Mar 2017 11:43:19 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-DNSBL-PBLSPAMHAUS: YES Subject: Re: [PHP-DEV] Type variants From: php@fleshgrinder.com (Fleshgrinder) On 3/12/2017 11:33 AM, Yasuo Ohgaki wrote: > DbC allows this kind of validation at development time. > I suppose you would like to check requirement at runtime always. > It would be nice to have feature, but I think > > something like __requrie() > > is better name for the method. > IMO, C# like getter/setter is better though. > > http://stackoverflow.com/questions/11159438/looking-for-a-short-simple-example-of-getters-setters-in-c-sharp > Hey Yasuo! :) Design by Contract is a nice thing, and you know that I would love to see it as part of the language. However, it is not really the solution to the problem that is being described here, since it is a valid state for an order to be empty. The stated Square-Rectangle example is a different beast, and there are many solutions to it. I probably would argue that Rectangle needs to extend Square and not the other way. Square has an extended functionality compared to Rectangle while being fully compatible. DbC would still be nice and would allow us to add real invariant, pre-, and post-conditions. I, as you might remember, would not go for a magic method but rather an extended block, like we see it for if-else or try-catch: class C {} invariant {} // one assert per line function f() {} requires {} // pre-conditions ensures {} // post-conditions -- Richard "Fleshgrinder" Fussenegger