Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91852 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 22329 invoked from network); 22 Mar 2016 16:43:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2016 16:43:46 -0000 Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wm0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:34974] helo=mail-wm0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/50-20537-14671F65 for ; Tue, 22 Mar 2016 11:43:45 -0500 Received: by mail-wm0-f49.google.com with SMTP id l68so161582536wml.0 for ; Tue, 22 Mar 2016 09:43:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=FrCUgSSNLnLvEyMnp9mptqT/1Y8t3lWg5yoe5mazhTI=; b=RzcjoarTl9mJWUgmNy7dLEO92CDhg5kkKjYK2w1PCMYZrF2IJhye6jyBH4QxkU849n x3TedVCFbpPA0hvuWrMG6nrhoAaqvot0vMlnXZLJdUeVjyLjxMcFS/P9xjskOlj4Ix7g 4kige8y0Hw7fZk11bWf8UtFdVU2LR9RMYJOrsGoUy8oJfqhPu//7e4b2TXBBLYN2+z0e ZN2+2KHRr/bSRRU90jwDFAr34HT5DpCRsIQvLiO8yVLJ5m9WlD+sVTWExWQX09VN1Fyz gxYznMXXB/XrQKXQpUCVA4tjDgmDCV57ts68LEjKO1VgYO+LM1h6/0dZ6AmkZ2rHjrYp C7nQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=FrCUgSSNLnLvEyMnp9mptqT/1Y8t3lWg5yoe5mazhTI=; b=WqRJrfKi0b1yf/LY6Hedj/JisTSxSzYYbvg/HA7yIVKKVU4iWeUw5KyGJsWxvYPjUP gbKqvsBmuVo9wy6MmgF0FRSfNKSBpvJgfKT/pB/xPtVIxClUX3pwB12oP3nJKuHPmqYU t23xiS5c6eTPinaPTJmpt7dzhWTCqZSlrpMZlXxJA13ih3XJrKhlUnJc6HTYYp/2kakO to+LVTqboX6cCcdzHCpjru4b/nBVMrUG3Jj87X71fLewkRVdFOzICY7r5whLsyxAat7P b71V8RVCeYAMow+ejvqg4nTv7H8M6SQZKG9ohULCJ0X4iTlAVXUSu8aFNcHVm2hOYT00 b3+g== X-Gm-Message-State: AD7BkJLKZwhcCwlwt5lo92rYcl4fE0a0Ml0/bT6DizYlLApa0VMv0EWkQKj2rRbPp4OOEw== X-Received: by 10.194.92.226 with SMTP id cp2mr36399999wjb.180.1458665022364; Tue, 22 Mar 2016 09:43:42 -0700 (PDT) Received: from [192.168.0.82] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id g3sm31133917wjw.31.2016.03.22.09.43.41 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 22 Mar 2016 09:43:41 -0700 (PDT) To: internals@lists.php.net References: <2070425.mznTmPgxij@mcmic-probook> <56F15D31.5070405@garfieldtech.com> Message-ID: <56F175F8.6080805@gmail.com> Date: Tue, 22 Mar 2016 16:42:32 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] RFC Proposal: Maybe monad and execution time polymorphic methods From: rowan.collins@gmail.com (Rowan Collins) Andreas Heigl wrote on 22/03/2016 16:25: >> 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. It depends on the context; sometimes, you are right, you would end up checking for validity early anyway, and an exception would be easier. However, the Null Object Pattern can simplify logic significantly where there is an obvious "null behaviour" that it can implement. Wikipedia gives the example of a recursive tree operation having to check for missing child nodes (https://en.wikipedia.org/wiki/Null_Object_pattern#Example); initialising the child nodes with Null Objects eliminates the check. The key point is that in some cases, the calling code *won't* break, because the Null Object can still adhere to the interface, just by returning appropriate empty values. In the tree node case, a NullTreeNode would always return further NullTreeNodes as children, a sub-tree size of 0, and either no-op or error if you attempted modification. Regards, -- Rowan Collins [IMSoP]