Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91975 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73202 invoked from network); 28 Mar 2016 06:14:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 28 Mar 2016 06:14:21 -0000 Authentication-Results: pb1.pair.com header.from=kelerest123@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=kelerest123@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: kelerest123@gmail.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:36859] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 74/5A-03797-CBBC8F65 for ; Mon, 28 Mar 2016 01:14:21 -0500 Received: by mail-oi0-f46.google.com with SMTP id r187so160673880oih.3 for ; Sun, 27 Mar 2016 23:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=R7OtArljkNHJRJVfqzVHA3a61E6aNy22PWEiS9EWccA=; b=JATUZFRXf7c9fdZqRSGHJpGqJhFiUEkSsFf9WGYJt9FHLxJiPpDlnzFhvil3P/nwIP z/CXHXURmqG1Y+ph1eiTf4lm7Bn6Itw/slgqFbbjvmKavcymMd8A3cff8yA+tZRYRtvs vIuizjiwwC3Y6Y3VDVSJOspWr9IJS6w0VJh/ocKhVKOYKObGZ9M7yfbXB/VwRKpIwj/x ZaAe/p1gwbENfvmU7wawkx1u9tP9+40PkLNcLIwMG3k9AShIbzlaqW5n2H4jK8VRFwAM tX5UIz8VF+99BdgJje4BJejYVCoV0Ug4cQem5MxKrtltU/jreIIIiFYYL5r5L+jIGDD7 uyEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=R7OtArljkNHJRJVfqzVHA3a61E6aNy22PWEiS9EWccA=; b=OR1JmOCAorMqLv7MSWzFJYJO4x0HPcQGuMGq3GduXX0QZ+cq41RzA2+e3yUUaofq0t KKWRP2rWswYJoL9CSd9KumXsHooBnxcAlgFOfRTJupsTWwuM7dpixVH663gW/zDl6I9Y tiKUwAg+iRWCeFMaeBOZ8wfA83qLxjZbNTCo5TY7mJ8vmdT5GOWYxgtwhPCLoZ8YIrt6 jCGrgeZ8xP2ZAo+MxKtszKSJ0SFsolke1IIiGAa/lecQQQGNY9GAtCwtrJPx992DV/2L Sj3liEs4vmWW8qv1+F60gFKnK4J14+yKdGBDBhQzyM75mBG5x8YPn5+3S3IWvmCGs3AU QrOg== X-Gm-Message-State: AD7BkJK1RwmeNF8t/yN8ZMarowqbQ+M9NMO2VgkjubwWon79QcmGq1hAU2SO81s48daZCqmksN3oMhJhmJWcsw== X-Received: by 10.157.46.101 with SMTP id c34mr7925052otd.66.1459145658568; Sun, 27 Mar 2016 23:14:18 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.118.228 with HTTP; Sun, 27 Mar 2016 23:13:59 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Mar 2016 11:43:59 +0530 Message-ID: To: Facundo Martinez Correa Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] RFC Proposal: Maybe monad and execution time polymorphic methods From: kelerest123@gmail.com (Kubo2) Hi Facundo Mart=C3=ADnez, I think the best solution to yourself described problem above would be the Null Object Design Pattern (https://en.wikipedia.org/wiki/Null_Object_pattern). In my opinion, NULL belongs to PHP and this language never aimed to become Java or similar. Jakub On 22 March 2016 at 01:34, Facundo Martinez Correa wrote: > Hello, > > I am reaching you in order to obtain feedback on this RFC proposal. > > I have been playing with PHP 7 for a project in the company that I am > currently working for. One of the many drawbacks that I saw in PHP was th= e > there were no types. With type hinting I had confindence again in PHP. Wi= th > return type hinting a wasn't able to resist to try it. So here I am, maki= ng > a whole new platform entirely in PHP 7, using type hints in everything. > Arguments and returns alike. Given my tendency to language purity imagine > my surprise when my code inadvertently tryied to sneak a NULL into a meth= od > expecting an object... And failing thanks to strictness in object and nul= l > treatments in the new PHP 7. "SWEET!" I yelled. > > Now imagine my dumbfoundedness when a Repository of mine tryed to return = a > NULL, and because it ought to return have returned a User, it threw a > TypeError. At first I said "sweet." But then I realized the problem. Ther= e > 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 i= n > many situations that I'm not proud of, all of them at the same time. > > So I want to "return a NULL". I want to express uncertainty, a > nonexistence. But I want to express that I will return something. And I > want to have this NULL checking at interpretation time. I want everything= , > and none of the drawbacks. As we say here in Argentina, I want the bread > and the cake. What can we do to have it? After a bit of thought the Maybe > monad came to me. > > My experience in Haskell reminded me of this. To have a structure than > represents uncertainty, is the best way to take away the responsibility > from NULL. To express it in no other way. But my experience in Java has > taught me that Optional of something is not a good way to tackle the > problem. I still have to check if my Optional isEmpty. I still have to > check for null. That is because Java has that type erasure after > compilation time that doesn't allow me to play nice with polymorphism. Bu= t > maybe PHP can. Maybe PHP will give me the polymorphism at execution time = to > discern an empty Maybe from the one that is not. So I don't have to check > for null ever again in my life. So my code can be free of nulls. So I can > express uncertainty and nonexistance, while I return a User from my > repository. > > I hope someone would like this idea. I'm also open to suggestions. > Kind regards > Facundo Mart=C3=ADnez --=20 Cheers, Kubis