Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:92425 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 61822 invoked from network); 18 Apr 2016 19:08:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Apr 2016 19:08:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 212.232.25.164 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 212.232.25.164 mx208.easyname.com Received: from [212.232.25.164] ([212.232.25.164:33419] helo=mx208.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 40/1D-11975-0B035175 for ; Mon, 18 Apr 2016 15:08:33 -0400 Received: from cable-81-173-133-226.netcologne.de ([81.173.133.226] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1asEX7-0002tY-JL; Mon, 18 Apr 2016 19:08:29 +0000 Reply-To: internals@lists.php.net References: <57103A46.6040803@garfieldtech.com> <5710BA79.5060108@lsces.co.uk> <57110DC5.8000007@garfieldtech.com> <571338E6.50507@fleshgrinder.com> <57145AF7.7060607@garfieldtech.com> To: Marcio Almada , Larry Garfield Cc: PHP internals Message-ID: <571530A5.8080703@fleshgrinder.com> Date: Mon, 18 Apr 2016 21:08:21 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="t8dQV3Pjc56xfsOMDw5XFRNjhpff6m03d" X-ACL-Warn: X-DNSBL-BARRACUDACENTRAL Subject: Re: [PHP-DEV] [RFC] Nullable Return Type Declaration From: php@fleshgrinder.com (Fleshgrinder) --t8dQV3Pjc56xfsOMDw5XFRNjhpff6m03d Content-Type: multipart/mixed; boundary="lCXoxusUEofGFiqJq9IaWQ323p7TNWt9O" From: Fleshgrinder Reply-To: internals@lists.php.net To: Marcio Almada , Larry Garfield Cc: PHP internals Message-ID: <571530A5.8080703@fleshgrinder.com> Subject: Re: [PHP-DEV] [RFC] Nullable Return Type Declaration References: <57103A46.6040803@garfieldtech.com> <5710BA79.5060108@lsces.co.uk> <57110DC5.8000007@garfieldtech.com> <571338E6.50507@fleshgrinder.com> <57145AF7.7060607@garfieldtech.com> In-Reply-To: --lCXoxusUEofGFiqJq9IaWQ323p7TNWt9O Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 4/18/2016 7:22 AM, Marcio Almada wrote: > 2016-04-17 23:56 GMT-04:00 Larry Garfield : >> Rather than debate the relative merits of Null as a concept, since I t= hink >> all agree removing Null from the language is not even a thing, what do= you >> think of my recommendation to NOT have the ? shorthand for "or null" o= n >> types, but keep the |null for union types? That is, if you want to re= turn >> Foo or null, you have to use the long-hand version: >> >> function foo($a) : Foo|null >> >> That >> >> 1) Allows for explicit or-null behavior. >> 2) Doesn't make it quite so easy, which hopefully discourages (but doe= s >> not prohibit) its usage. >> 3) Neatly avoids the ?Foo / Foo? question entirely. >> >> I think that's a win-win arrangement. >> > I can agree with that. >=20 > Language design wise, if you have no way to forecast how language featu= res > independently proposed are going to interact then it's a good idea to h= ave > a converging strategy. Fortunately, this seems to be happening almost > spontaneously towards union types representation, as in the "multiple > catch" RFC (https://wiki.php.net/rfc/multiple-catch) now in voting phas= e. >=20 > Even if we decide not to commit to a full union types implementation no= w, > the design process will be much easier in the future if we decide to us= e > Foo|null instead of Foo? or ?Foo and we will not end up with 2 or 3 way= s > alternative to declare the same thing. >=20 I actually do not see a problem with the shorthand notation. I am usually an extreme opponent of duplicated or aliased functionality because it increases the cognitive load to keep all this crap in your mind. This is however a useful shortcut and shortcuts are good things in terms of usability if done write. Think of + vs. right click > copy (or any other example of useful keyboard shortcuts). The usage of *null* as an union type is the most common case compared to all the others that are truly rare in comparison. There are other shortcuts in PHP that are perfect: - Iterator vs. Generator: they can achieve the exact same thing but slightly different and a generator can almost always be used to replace an iterator with less code, even if the special effects of it are irrelevant. - `$x =3D $x + $y` vs. `$x +=3D $y`: we have many of those and that is ju= st fine as it is. - `$x =3D $x + 1` vs. `++$x` vs. `$x++`: ditto - `