Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:91983 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43481 invoked from network); 29 Mar 2016 02:15:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Mar 2016 02:15:28 -0000 Authentication-Results: pb1.pair.com smtp.mail=fnmartinez88@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=fnmartinez88@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.161.169 as permitted sender) X-PHP-List-Original-Sender: fnmartinez88@gmail.com X-Host-Fingerprint: 209.85.161.169 mail-yw0-f169.google.com Received: from [209.85.161.169] ([209.85.161.169:35942] helo=mail-yw0-f169.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 57/C0-37399-F35E9F65 for ; Mon, 28 Mar 2016 21:15:28 -0500 Received: by mail-yw0-f169.google.com with SMTP id g3so2530287ywa.3 for ; Mon, 28 Mar 2016 19:15:27 -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; bh=qlCl/1Dv0+XZECiZpqjjtZ7jzuLdLzlsLllshNW2TrQ=; b=KV6qauDIGSkllHRVwivtAhlQVs3MGdRrMB61MKQaAQf0zst8m4tGH0f5pOaJKICfGl sg8YF4wcpS1mUMwkTtbxnnC6I/+c9sqR0RRbGl5aGDZgxepnqYDr71xnQvMOJ7xGojup oxd5DCY9ipM67McdVyxhrqzh/tKe+5ucob2ukcC89E+QoPFqAfz4T4P0wZaRsGIY0V53 N58L/AI4a3VViAf19j/aw+rqHRCltPuIYw3sJt+CWcfoTL8tH46cftVMapXrErsxm3vp SXbScLIww/DVYLzO4Wbjc5dDVbNQX2JBAsZnk+IUoq1W/w02o51hvE9bWy0q2pvjH4rt MpMw== 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; bh=qlCl/1Dv0+XZECiZpqjjtZ7jzuLdLzlsLllshNW2TrQ=; b=XKEMYYgnSrK+SwoRX4c5HJCGJPyXFF0PUj8KaJpKmE095n0NpUTvm0GQlkchimOGte dMfSq3qUANj1qOV2+9GXOUOOKVWilNVm4Xp93KUwlRhyXy92cOj1US78KQRcO0lkU7sS keIUZ9nbMJB0RAkOMLAgua18ISZYJRewE5IUyZ6VLgEWAe9Hfxijdy/R4+ypktYPhrw1 6NKPlzorUpKKNJIaDrev5XnZQffvMZE7AyoP2/Ybz6/AmDMcxnT3eWlNFUb/zbzYS4aR NxcM0QOLaOzrTyTAUNvimtvN696InVJLiyjWqIw8q1f4Nte2QQm4zuHuFCEgA3NA3HdH y4bQ== X-Gm-Message-State: AD7BkJKkRFoThhSIHXU/domYlyb0v0LTYOB0tx4LZ0WNv1LwFquHbGUjkwECKKsPJPAQzgb+M581cE0/mqqlzA== X-Received: by 10.129.31.139 with SMTP id f133mr3342058ywf.288.1459217724307; Mon, 28 Mar 2016 19:15:24 -0700 (PDT) MIME-Version: 1.0 Received: by 10.37.79.3 with HTTP; Mon, 28 Mar 2016 19:15:04 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Mar 2016 23:15:04 -0300 Message-ID: To: Kubo2 Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a114144381b80f0052f269a42 Subject: Re: [PHP-DEV] RFC Proposal: Maybe monad and execution time polymorphic methods From: fnmartinez88@gmail.com (Facundo Martinez Correa) --001a114144381b80f0052f269a42 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Jakub, Regarding the Null Object, I believe it to be a second hand solution. Having a Null Object that returns 0, null, "" or false for every method call, or a nil that acts as in Objective C that doesn't tell you when is being poked the wrong way is the first step into madness. It will never tell you about runtime errors, and you will find those errors once some data that is being outputed from the systems gets into your DB/Logs/Screen/whatever and just by chance you see that and say "Hey! that wasn't supposed to be there!". Then all hell breaks loose, and you start chasing code that never happens because your data will never be wrong and will always gracefully degrade. I believe that pattern is a bad pattern and humanity should feel bad about it. In fact, I believe it will be a feature that will drive people away from PHP and not towards it. Besides, the whole point of this idea I brought was to avoid checks that the interpreter could catch. If I return a Null Object, I'm forced to always ask for it. Now, regarding the "NULL belongs to PHP and this language never aimed to become Java" part. That is interesting because a) I never wanted to be Java, and in fact, I want it to be as more different to it as possible because I know what is bad and good and Java. b) As far as I remember, from the beginning of PHP, NULL was as in C a rename for 0. You could use 0, FALSE and NULL indistinctly. I'm not saying to eliminate null. Null does serve some other purposes, specially when you are managing memory, or bits, or whatever. I'm talking about making it represent less things and make the language more expressive. I hope transmitted my idea right. Thanks for the reply, Facundo On Mon, Mar 28, 2016 at 3:13 AM, Kubo2 wrote: > 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 > the > > there were no types. With type hinting I had confindence again in PHP. > With > > return type hinting a wasn't able to resist to try it. So here I am, > making > > a whole new platform entirely in PHP 7, using type hints in everything. > > Arguments and returns alike. Given my tendency to language purity imagi= ne > > my surprise when my code inadvertently tryied to sneak a NULL into a > method > > expecting an object... And failing thanks to strictness in object and > null > > treatments in the new PHP 7. "SWEET!" I yelled. > > > > Now imagine my dumbfoundedness when a Repository of mine tryed to retur= n > 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. > 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 f= or > > 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. > > > > 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 brea= d > > and the cake. What can we do to have it? After a bit of thought the May= be > > 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. > But > > maybe PHP can. Maybe PHP will give me the polymorphism at execution tim= e > to > > discern an empty Maybe from the one that is not. So I don't have to che= ck > > for null ever again in my life. So my code can be free of nulls. So I c= an > > 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 > > > > -- > Cheers, > Kubis > --001a114144381b80f0052f269a42--