Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91851 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20680 invoked from network); 22 Mar 2016 16:36:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2016 16:36:09 -0000 Authentication-Results: pb1.pair.com smtp.mail=larry@garfieldtech.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=larry@garfieldtech.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain garfieldtech.com from 66.111.4.25 cause and error) X-PHP-List-Original-Sender: larry@garfieldtech.com X-Host-Fingerprint: 66.111.4.25 out1-smtp.messagingengine.com Received: from [66.111.4.25] ([66.111.4.25:42812] helo=out1-smtp.messagingengine.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/00-20537-B6471F65 for ; Tue, 22 Mar 2016 11:35:56 -0500 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 0FA16211A0 for ; Tue, 22 Mar 2016 12:35:53 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute4.internal (MEProxy); Tue, 22 Mar 2016 12:35:53 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=hB+zkmIbawjAYOG E5bz+aox4KG0=; b=QP5AxtLlXS0rtiHmurybflWSybt4HkvcxIPtGmHb3bH8hwI JUsLkNO90mhYGU76lllvFgm9hN8uKZ86h0P1t//MSJzIWavueXEEqKYN8fppmX+1 eutfrc05dQg4/xqsHEHcbyv1Jlf2xHzMEWP1v79Vq04KM3eWfm+5Bq95cAAs= X-Sasl-enc: fc+ZmFuS+S+aZCBgPjDPSEE0l5H4Ib1lVl5FDhvm4PKb 1458664552 Received: from Crells-MacBook-Pro.local (unknown [63.250.249.138]) by mail.messagingengine.com (Postfix) with ESMTPA id B6C8F6800F5 for ; Tue, 22 Mar 2016 12:35:52 -0400 (EDT) To: internals@lists.php.net References: <2070425.mznTmPgxij@mcmic-probook> <56F15D31.5070405@garfieldtech.com> Message-ID: <56F17468.6010205@garfieldtech.com> Date: Tue, 22 Mar 2016 11:35:52 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.0.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] RFC Proposal: Maybe monad and execution time polymorphic methods From: larry@garfieldtech.com (Larry Garfield) On 3/22/16 11:25 AM, Andreas Heigl wrote: > >> Am 22.03.2016 um 15:56 schrieb Larry Garfield : >> >>> On 3/21/16 10:23 PM, Côme Chilliet wrote: >>> Le lundi 21 mars 2016, 17:04:30 Facundo Martinez Correa a écrit : >>>> But then I realized the problem. There >>>> are many times where we need uncertainty. Code is a reflection of reality, >>>> and as such, it must reflect uncertainty. NULL is a good enough way to >>>> express nonexistence, albeit a bad one. We have been using it in code for >>>> years, but it is also used to say many things. Things that cause >>>> uncertainty in the code. I receive a null, does it mean it doesn't exists? >>>> That it will exist? Should I allow it? Is it a good value? I for sure don't >>>> know. And in my experience, I have used it for many of those cases. And in >>>> many situations that I'm not proud of, all of them at the same time. >>> If your function is supposed to return a User and can’t, maybe it should throw an Exception. >>> Just wanted to point out it can be a good alternative to returning NULL for error handling. >>> >>> Côme >> In the PHP 7 and typing presentations I've been giving[1], I've advocated either: >> >> 1) Throw an exception if the rest of the code is going to break anyway. >> 2) Define an empty object with matching interface if you want an equivalent of 0/empty string. > When code expects a user-object but can't get one it'll break. Throwing an exception makes it easy to react to that. But when the code has to check whether that's a mocked user object or a real user object it's about as good as returning null or eliminating the return type altogether as you have to build the code around that returned value you can't really use. > > So in my opinion either return a proper object/type or throw an exception. An "empty" object as I describe it isn't really a proper empty object unless it does satisfy the type and interface, such that you don't need special handling for it. The example I use in the slides is an Address object, with AddressInterface, whose "empty" implementation just has empty strings for all the various parts of it. That will work in some use cases but not others. It's up to the developer to determine if a reasonable empty object would work in their situation or not. If it doesn't, I agree, an exception is the answer. In any event, it sounds like a native monad won't work well in PHP so we're now drifting off topic. :-) -- --Larry Garfield