Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82229 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52753 invoked from network); 9 Feb 2015 06:50:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Feb 2015 06:50:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.53 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.192.53 mail-qg0-f53.google.com Received: from [209.85.192.53] ([209.85.192.53:58196] helo=mail-qg0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/60-50460-BA858D45 for ; Mon, 09 Feb 2015 01:50:20 -0500 Received: by mail-qg0-f53.google.com with SMTP id f51so20095846qge.12 for ; Sun, 08 Feb 2015 22:50:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=+Gkjb7FzRbbXcZ8qwuoBGfvwesfqRI1EoqqTnqnNMkM=; b=tDZdiIoNAdo4jAY8cCpp1wCX8Un2NAFhyTuo1+64Gn81Irg8KtmM/y61UUsi5ZO7WM Wgoykc+gaCQOXbm+lCgmNaRC8AQ9pDsixhwSu4qndtb74+jWQYTvyNFzm/zIddIlRn+E RUX35Zt7Nt2ZChvaTUlpWjYmNyT07QKsefmUVxyygFnJDYC/ogUmP9OCAqcO8xWqJxqc qh75Ne3aAoxOb19lANbeTcgYJ3W/bvOu7tWijhkuWEeicQrO4cgopQvImG+hjVwR8BlO xcMeiafhSjaLkvov1zYofxparSEQ4po0bxES0jeZaZvBFFJQNi0xtrHuhw7rvvFV6rtz zCAQ== X-Received: by 10.140.42.83 with SMTP id b77mr31659585qga.43.1423464616444; Sun, 08 Feb 2015 22:50:16 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.229.28.72 with HTTP; Sun, 8 Feb 2015 22:49:36 -0800 (PST) In-Reply-To: References: Date: Mon, 9 Feb 2015 15:49:36 +0900 X-Google-Sender-Auth: 7Qfd-gfXgM4lAurfvgfidVxzFh4 Message-ID: To: Daniel Lowrey Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c13054d04a7e050ea22e2f Subject: Re: [PHP-DEV] Re: Design by Contract From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a11c13054d04a7e050ea22e2f Content-Type: text/plain; charset=UTF-8 Hi all, On Mon, Feb 9, 2015 at 3:41 PM, Yasuo Ohgaki wrote: > On Mon, Feb 9, 2015 at 2:12 PM, Daniel Lowrey wrote: > >> First, let me say that I have voted against the current scalar types RFC. >> Please do not let that color your evaluation of the rest of this message >> ... >> >> I want to go on record (for the n-th time) as being unhappy about any >> proposal that forces me to use php.ini. IMHO if it doesn't work with `$ >> php >> -n` then it's not a solution, it's a hack. Yes, I understand that opcodes >> > > "php -n" works (Well, we have data.timezone, though) with DbC. It should > execute script in production mode. > > >> can't be removed (perf, yay!) without knowing ahead of time from php.ini. >> But the opcode removal difficulty should not be understood as a "well we >> just have to do it this way," situation. Instead it ought to serve as a >> warning sign that this is not the right answer. Type checking is not a >> configuration-level issue; it is a language-level issue. Shoehorning it >> into the .ini file is just another band-aid on a broken arm. >> >> We tend to hold new proposals to the litmus test, "can this be effectively >> accomplished in userland already?" Well, yeah, in this case it really can. >> Making assertions optionally throw isn't some great advancement: >> >> // I can do this now >> if (!is_string($str) && DEBUG) throw new Exception("you bad coder bro"); >> > > In order to make robust and secure apps, functions/methods is better to > have > constraints. Type check is one of them. There are many people argue "This > language is secure and robust because it has _static_ types". > > > // I'm all for brevity but does this really need an RFC? >> assert(is_string($str), "you bad coder bro"); >> >> That's a pretty insignificant, surface-level improvement. Mostly I just >> disagree with the assertion (see what I did there?) that this DbC RFC is >> remotely the same as what the scalar types RFC is trying to accomplish. >> And >> it certainly doesn't have universal support. >> > > DbC is not surface level change. It change application/code design a _lot_. > In fact, DbC controversial what we have today and paradigm change. > > With modularized design, the more code is consolidated, the better code is. > Therefore, parameter validity is checked deep into the code for example. > Since > these functions are rather simple basic functions that are used by many > codes, > the parameter validity is checked _many_ times over and over. This slows > down > execution. > > Solution? We should get rid of simple parameter validity checks from code > written > in basic functions. However, if we simply get rid of the check, we'll end > up > with too many bugs because caller forget about callee > specifications(contracts). > > Here comes DbC, once we have contracts for pre/post conditions. We are > safe from calling functions with invalid parameters during development, yet > we have optimum performance for production since there is zero contract > checks > with production mode including opcode. > > My explanation is poor. So please research what is DbC more deeply. > I think you'll like it once you understand the whole concept. Many > languages > have DbC support, in fact almost all languages, because DbC is extremely > (It's extreme for me) useful to develop fast/secure apps. > I forgot to mention the most important. DbC changes application/program design and the way of programming. It changes PHP applications being more robust/secure and faster. It changes PHP application development and testing, it will be more efficient with DbC. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a11c13054d04a7e050ea22e2f--