Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72261 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94636 invoked from network); 5 Feb 2014 10:53:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Feb 2014 10:53:29 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.169 as permitted sender) X-PHP-List-Original-Sender: yohgaki@gmail.com X-Host-Fingerprint: 209.85.217.169 mail-lb0-f169.google.com Received: from [209.85.217.169] ([209.85.217.169:33068] helo=mail-lb0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 39/33-09402-72812F25 for ; Wed, 05 Feb 2014 05:53:28 -0500 Received: by mail-lb0-f169.google.com with SMTP id q8so173777lbi.28 for ; Wed, 05 Feb 2014 02:53:23 -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=+7yKqzEJeA1AdPXuE7vxXo8jMhXlFyFIKy/onGmXPFQ=; b=I+g3p5W2lq9NguyARzSLxST0ItQPCggiQ2YsJM5rbRgsWnTtOWm/UHkxnkYu9JA/kt CCo0riqotrHKI2NS6TWDgIWhGnVgHNudAnmJnEb9Uc0c1Hu479rRdpKBQ0t5OMr+JbSz eCyfWMRfi6Bf5tWlaw6ACmX8xA+avgbXK6Qe7dyMmatYin93p5797bAUlF0VYg0AAnEw 6AZ7s532ybq8rGNvBajty+tTl2UVYYf4iI0jcIbkNqPrFgk5+SQFXcSyiJ55xKYKmknn xBIqA+9KYm9sZ5p/fqXh8/vRLxi/EKKC4ESi/VwlHZjc7zFzu+1YHVea6PL6vrBFK5wy xFbg== X-Received: by 10.152.10.70 with SMTP id g6mr41258lab.65.1391597603491; Wed, 05 Feb 2014 02:53:23 -0800 (PST) MIME-Version: 1.0 Sender: yohgaki@gmail.com Received: by 10.112.199.37 with HTTP; Wed, 5 Feb 2014 02:52:43 -0800 (PST) In-Reply-To: <52F20C7C.3040803@lsces.co.uk> References: <52EF4BF8.60005@sugarcrm.com> <52F14C66.3030806@gmail.com> <52F15B62.1070006@gmail.com> <52F20C7C.3040803@lsces.co.uk> Date: Wed, 5 Feb 2014 19:52:43 +0900 X-Google-Sender-Auth: yI8ofWm-5RxTaq0zN7UdNGirARA Message-ID: To: Lester Caine Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a1132ee92d3933704f1a690b4 Subject: Re: [PHP-DEV] Declare minimum PHP version required? From: yohgaki@ohgaki.net (Yasuo Ohgaki) --001a1132ee92d3933704f1a690b4 Content-Type: text/plain; charset=UTF-8 Hi Lester, On Wed, Feb 5, 2014 at 7:03 PM, Lester Caine wrote: > Yasuo Ohgaki wrote: > >> Yes. New assert() is as efficient as declare(). >> I cannot wait to use new assert()! >> > > Yasuo > Please can you explain why you think this is so essential? The only place > I can think that I would use this I ALSO need to advise the users that > there is a problem. Adding 'assert' which apparently only has use while > debugging just seems wrong. Alright I add vd() and similar myself when > debugging code rather than using a 'debugger', but if I need to test > something only at debug time then I'll just add code and remove it when I > have sorted the problem. If it is a problem which will stop the code > running, then it needs a proper response in the workflow anyway. > Since I'm a developer, I do not pay much attention once code hits production. (I do care errors a lot, though. I catch all errors/exceptions as a sign of fatal errors) Therefore, assert() is enough for me to alert users(developers) to notify something wrong during development. In contract, I think you pay much attention to production environment. I think it is very important for us (PHP internal developers) also. I guess you're dealing with a lot of end users and getting annoyed by PHP changes. Checking requirements at compile time would be valuable for you as you may configure PHP to display completely broken scripts for the environment. (i.e. Display compile error) For this use, declare() is the best solution. We might be better to think again for your use. ADOdb and smarty both have switches to enable debugging which can be > switched on as required at runtime and I can't see any reason they would > switch to using assert instead? Assertion can be used to development time only checks so that programmers notice silly mistakes, passing invalid arguments for function, range check, type check, format check, pre/post condition check, etc. Even for ADOdb or Smarty developers, they have conditions that should be checked only when they are writing new code. I like DbC in D and other languages. For example, D supports "in" as precondition check, and "out" as post condition check. long square_root(long x) in { assert(x >= 0); } out (result) { assert((result * result) <= x && (result+1) * (result+1) >= x); } body { return cast(long)std.math.sqrt(cast(real)x); } With contract programming, caller has a responsibility to pass arguments that meets precondition contract and callee has responsibility returns a result that meets post condition contract. If whole program is made this way, callee does not have to check pre/post condition at all as long as input for program is validated strictly. With contract programming, lower level functions does not have to check arguments under production environment at all, thus program runs much faster than traditional design yet it achieves robustness. (in theory. We're better to leave some checks for fatal error especially for security related matter) Assertion that does not have run time overheads at all is very cool thing for PHP developers to write robust and fast applications, especially for developers who prefer micro frameworks. (Missing pace for PHP is pre/post condition check, but it's much better than before and it can work round. Comprehensive frameworks have contract via annotation, etc at user land.) I agree that assert() may not help you much from your users asking "I got blank screen!", but it helps developers a lot. It also may help you if your user can change INI setting to see what's wrong. Does this answer your question? Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --001a1132ee92d3933704f1a690b4--