Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82019 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 83083 invoked from network); 6 Feb 2015 07:39:18 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2015 07:39:18 -0000 Authentication-Results: pb1.pair.com smtp.mail=francois@tekwire.net; spf=softfail; sender-id=softfail Authentication-Results: pb1.pair.com header.from=francois@tekwire.net; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain tekwire.net does not designate 212.27.42.2 as permitted sender) X-PHP-List-Original-Sender: francois@tekwire.net X-Host-Fingerprint: 212.27.42.2 smtp2-g21.free.fr Received: from [212.27.42.2] ([212.27.42.2:14113] helo=smtp2-g21.free.fr) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/57-45146-4AF64D45 for ; Fri, 06 Feb 2015 02:39:16 -0500 Received: from moorea (unknown [82.240.16.115]) by smtp2-g21.free.fr (Postfix) with ESMTP id 646114B014A; Fri, 6 Feb 2015 08:35:53 +0100 (CET) Reply-To: To: "'Adam Harvey'" Cc: "'PHP Internals'" References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> In-Reply-To: Date: Fri, 6 Feb 2015 08:39:08 +0100 Message-ID: <02b801d041df$fdf775b0$f9e66110$@tekwire.net> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQJMIZG9mXkdirFXmuP9r5ZK3xIuzQIp9d7Am9otEFA= Content-Language: fr X-Antivirus: avast! (VPS 150205-1, 05/02/2015), Outbound message X-Antivirus-Status: Clean Subject: RE: [PHP-DEV] [VOTE] Scalar Type Hints From: francois@tekwire.net (=?utf-8?Q?Fran=C3=A7ois_Laupretre?=) +1 > -----Message d'origine----- > De : adam@adamharvey.name [mailto:adam@adamharvey.name] De la part > de Adam Harvey > Envoy=C3=A9 : vendredi 6 f=C3=A9vrier 2015 02:23 > =C3=80 : Andrea Faulds > Cc : PHP Internals > Objet : Re: [PHP-DEV] [VOTE] Scalar Type Hints >=20 > On 6 February 2015 at 04:14, Andrea Faulds wrote: > > At long last, I=E2=80=99m going to put the RFC to a vote. = It=E2=80=99s been long enough - I > don=E2=80=99t think there needs to be, or will be, much further = discussion. >=20 > True, and I probably won't respond to any replies to this because we > don't need more noise, but I do want to explain my -1 vote. This is > long and rambling. I apologise. I've posted a formatted version of > this at https://gist.github.com/LawnGnome/354ca07f1799ff88fc35 in case > it's easier to read. >=20 > In no particular order, my issues with this RFC: >=20 > ## The declare switch >=20 > Adding the cognitive overhead for each file for developers to have to > remember whether they have to cast a value before passing it to a > function or if PHP will automagically do that for them is a bad thing. > Of course, in a small, well compartmentalised file, or a single > developer code base, it wouldn't be a problem. Unfortunately, a lot of > PHP projects aren't that tidy. (Probably most of them, in fact.) >=20 > I also disagree with the comparisons that have been drawn on Internals > between `declare(strict_types=3D1)`, `use strict`, and `from = __future__ > import foo` statements. They're not the same thing at all: >=20 > * `use strict` is ultimately about code quality =E2=80=94 am I doing = something dumb? > * `from __future__ import foo` is ultimately about features =E2=80=94 = yes, I > want to opt-in for the new shiny. > * `declare(strict_types=3D1)` isn't either of those, although it might > superficially appear so =E2=80=94 what it's really about is "I reject = your > philosophy and substitute my own" in terms of typing. >=20 > There are structural decisions we can and should let our users make. I > believe this isn't one of them: allowing users to fundamentally change > the typing semantics of a language on a module-by-module level is, in > my opinion, insanity. Languages have to be opinionated about this sort > of issue: if they weren't, there'd only be one programming language > and it would have 800 switches to configure before you could write a > line of code. This sort of decision is the whole point of designing a > language: abdicating it by providing a switch is effectively us > shrugging and saying "sure, whatever, we don't care, so now we'll make > you care". >=20 > ## Strong typing >=20 > This ties into the previous point: for scalars, PHP has never been a > strongly typed language. I was once on the train of strict typing > being universally better =E2=80=94 if you know that you always have an > integer, you never have to worry about a bad conversion, right? And, > if I was designing a language from scratch, I'd probably still feel > that way. >=20 > That language wouldn't be PHP, though. PHP is unapologetically weakly > typed from top to bottom. Designing a feature to break that would be > bad enough. Designing a feature to optionally break that is insidious. > If you care about whether the zval IS_STRING, you can check that > today. Encouraging our users to care goes against the entire > philosophy of the language. >=20 > To be clear: yes, we have problems in our type conversion matrix. The > fact that `"21 Jump Street" =3D=3D 21` is an issue (particularly = because > it's silent), and we should be talking about that. But strong typing > is not the solution. >=20 > ## Caller versus callee >=20 > Making the caller responsible for choosing the type behaviour is a > clever hack. (No pun intended, Facebookers.) I find the idea > intriguing from an academic perspective. Unfortunately, as with the > above point, this isn't consistent with PHP as a language that's > existed for 20 years and had type hinting in its current form for over > 10 years. If we accept this, then we only widen the gap between scalar > values and array/object ones: for one set of type declarations, the > behaviour is determined entirely by the callee, and for another, it's > determined by both the callee (via the type hint) and the caller > (whether it will be converted or not). >=20 > ## So what do we do for 7.0? >=20 > From where I sit, we had a good solution: it was the 0.1 version of > this RFC. It behaved like PHP should behave, respected PHP's long > standing scalar type handling and conversion rules, but most > importantly, it solved the **actual** problem scalar type hints are > supposed to solve in the simplest possible way: >=20 > Can I guarantee that my function that expects an integer will > really get an integer? >=20 > I don't think that adding complexity on top of that helps anyone in > the long run. Yes, we get to tick some extra boxes =E2=80=94 "we = support > strong typing", "we support weak typing", "we put the user in control" > =E2=80=94 but at the cost of having a language that not only supports, = but > advertises multiple, inconsistent behaviours, requires users to be > aware of conversion minutiae that they shouldn't have to be mindful > of, and doesn't do anything to solve the actual problem above. >=20 > Adam >=20 > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php