Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87758 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50117 invoked from network); 17 Aug 2015 08:07:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Aug 2015 08:07:40 -0000 Authentication-Results: pb1.pair.com smtp.mail=netmo.php@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=netmo.php@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.41 as permitted sender) X-PHP-List-Original-Sender: netmo.php@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-la0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:35740] helo=mail-la0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 15/B2-63805-A4691D55 for ; Mon, 17 Aug 2015 04:07:39 -0400 Received: by lahi9 with SMTP id i9so73837553lah.2 for ; Mon, 17 Aug 2015 01:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=lGDgECCAmEwGuiGEY0VayWGajR9drxU/wdzoGwfGT9M=; b=JoEJWxS0ZfPZ3F1GzBIpVz8To09gxDxi35uvNhE7xX+eCIFnIjONNmHZNdTS9EBma9 h/+PxNjLzucwECqb10MzOxTjg3H2GEBzTkGp9HNSdYAkRwQ4Q0r2ekZW8hEcYXP1kBr3 x7zOgZDQFHgN3+UUd1bNvniEptKd8VEcvtHAsUZwPsB8AKMXrS+7sUYfxocFgawSeMxg lFq70GtW3HU86jNVNgoM0dwzp/lAdGTuZS44L7iueGZiOWhKmOujNxO3zfhmSTmNAXOP 0LJqZ9MZWDCcrIKSVIGfRfP7ZrdwqrgGzFDNAtBnQznPCzrAfX9ajLRnVEigFKT+l4a7 xcTQ== MIME-Version: 1.0 X-Received: by 10.152.6.194 with SMTP id d2mr128284laa.93.1439798855942; Mon, 17 Aug 2015 01:07:35 -0700 (PDT) Received: by 10.114.216.129 with HTTP; Mon, 17 Aug 2015 01:07:35 -0700 (PDT) Date: Mon, 17 Aug 2015 10:07:35 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=089e013d186a5b459d051d7d4bb4 Subject: Additional ideas about the design by contract RFC From: netmo.php@gmail.com (Net Mo) --089e013d186a5b459d051d7d4bb4 Content-Type: text/plain; charset=UTF-8 I like the idea a lot, although I'm not so sure of the proposed syntax. I would make it less specific. Preconditions/Postconditions assertions are indeed useful but the functionality could be extended to regular checks as well by making the error user defined. Plus, I would prefer having named checks rather than having the expression repeated every time: it's great for reusability and signatures would be shorter (... they are very lengthy already). For instance: public function offsetGet(int{NonNegative} $offset){} function NonNegative(int $offset){ if($offset < 0) throw new WhateverError; } If one wants them to act like assertions could still write: function NonNegative(int $offset){ assert($offset >= 0); } Some blue sky thinking code is here: http://pastie.org/10355629 Although, I'm not sure whether the validation function should be a simple named function or a type: public function baz(Foo{MyChecker} $foo); interface MyChecker extends Validator{} class MyStrictChecker implements MyChecker{ function check($value){ if($value < 10) throw new MyException; } } class MyDevChecker implements MyChecker{ function check($value){ assert($value >= 10); } } That could be useful, I believe, but kind of makes "the contract" too abstract. What do you think? Forgive my poor english. --089e013d186a5b459d051d7d4bb4--