Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82367 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84044 invoked from network); 10 Feb 2015 11:44:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Feb 2015 11:44:55 -0000 Authentication-Results: pb1.pair.com smtp.mail=lisachenko.it@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=lisachenko.it@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: lisachenko.it@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:50464] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/B4-47508-33FE9D45 for ; Tue, 10 Feb 2015 06:44:52 -0500 Received: by mail-wi0-f176.google.com with SMTP id hm9so13721508wib.3 for ; Tue, 10 Feb 2015 03:44:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QVyB56UkWMawEe7lYbr6TGOzQD7bTQpoFoSitrzhwDY=; b=raYLCpmGXJN0LdtF/R/mLYy8NH3pO6sWgQVVtjzDeoAqA6S9q3BxW+dq/52Bdm+7Zq OI23VQbz2y6hKoOPxOxCamOn/dHhkPF2IhxgU60r5N6IevWrLAx4wUzlScucR0hMYoxQ 1oh6w8hII9Nx1bmEc2fgECVerJFKasChyvLccPAqd0LLvzoHCU6yD/IK/aizE6j9b5sk 1Gkocbj5NX9Akb5Hcngk+hC3lMxPSOn/v16fIPby6SoL35uPRQZJ5Y0ypg1K6WeYaaVF jgf8VMPPK2Sy6UZgAo/ZGO9PlVBhso3j20lb8FdNOR9s6h9BiKj0gO3IHktvA92XD+x+ z29w== MIME-Version: 1.0 X-Received: by 10.194.191.228 with SMTP id hb4mr14983405wjc.116.1423568688784; Tue, 10 Feb 2015 03:44:48 -0800 (PST) Received: by 10.194.154.229 with HTTP; Tue, 10 Feb 2015 03:44:48 -0800 (PST) In-Reply-To: <54D9DE4B.7030509@lsces.co.uk> References: <54D7ED22.3080001@gmail.com> <54D9DE4B.7030509@lsces.co.uk> Date: Tue, 10 Feb 2015 14:44:48 +0300 Message-ID: To: Lester Caine Cc: PHP internals list Content-Type: multipart/alternative; boundary=047d7b8750be022c72050eba6a72 Subject: Re: [PHP-DEV] Design by Contract From: lisachenko.it@gmail.com (Alexander Lisachenko) --047d7b8750be022c72050eba6a72 Content-Type: text/plain; charset=UTF-8 Hello, internals! DbC is good thing, but the way you want to do this via language changes is really awful. Why do you want to add more custom features into the language, instead of providing an API to extend it in a more natural way by framework developers? Many existing implementation of DbC is just kind of bytecode compilers and IDE tools. Main idea of DbC is to help developer with writing a better code without errors. But then, during compiling (production mode) all checks will be removed. Am I one who think that this code is looking weird? public function destroy($id) require(strlen ($id) > 10) return(is_bool ($>)) { @unlink ($this->path . $id); } This part of code is breaks block structure of function, adding custom part of code, which is not related to the function logic itself. Instead of doing this weird syntax only for personal fun, just think about more general usages of parser and assertions. As you know, I'm working with aspect-oriented programming in PHP and have a library for that. And it wasn't easy to implement it, because there is no API for that from PHP. This techniques can be also used for DbC as well. So, my suggestion is to drop current rfc and start more general one, called "PHP Language Extension API", which will include an API for defining metadata and API for opcode manipulation. Compare previous example with another one with plain metadata: [Require => strlen ($id) > 10)] [Return => is_bool ($__result)) public function destroy($id) { @unlink ($this->path . $id); } This code then will be parsed and PHP hooks that were registered by register_parser_extension() will be called and extension will produce a valid opcodes for that for method destroy(), by modifying AST-node. This way is much elegant and can be reused later for many features, like Design By Contracts, native SQL support syntax in PHP (LINQ), Aspect-Oriented Programming, hooks and much more. Just stop to create custom features in the engine itself and give this work for framework and PHP-extension developers. 2015-02-10 13:32 GMT+03:00 Lester Caine : > On 09/02/15 23:47, Yasuo Ohgaki wrote: > > The RFC draft is ready. > > https://wiki.php.net/rfc/dbc2 > > > These contracts are evaluated development time only. Therefore, there is > no performance penalty with DbC. > > Sorry but that makes no sense to me at all. If this is something only to > use with an IDE then why does it have to have anything that is visible > at 'run time'? This seems to be going down the track of "we will be > compiling this eventually" and that is just not what PHP *IS* about. > These are more hints, but assume that at runtime what they define is not > relevant? > > ALL of this discussion on type hinting how ever it is handled is simply > sidestepping the major plus on PHP with associative arrays. I see no > point expanding every database record read to 'magic access functions' > for multiple variables and it *IS* the scalar values stored in these > arrays that needs the 'hint/constraint' control. > > I am getting even more confused about just what all the different > factions are trying to achieve. Yes I know I can totally ignore all of > it, but with my current tools losing traction because of all the 'better > ways of working' what in my opinion IS the best way to allow different > factions to add their own pet style is drowning simple clean solutions > such as docblock. > > -- > Lester Caine - G8HFL > ----------------------------- > Contact - http://lsces.co.uk/wiki/?page=contact > L.S.Caine Electronic Services - http://lsces.co.uk > EnquirySolve - http://enquirysolve.com/ > Model Engineers Digital Workshop - http://medw.co.uk > Rainbow Digital Media - http://rainbowdigitalmedia.co.uk > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --047d7b8750be022c72050eba6a72--