Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81994 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26996 invoked from network); 6 Feb 2015 01:23:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Feb 2015 01:23:47 -0000 Authentication-Results: pb1.pair.com header.from=adam@adamharvey.name; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=adam@adamharvey.name; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain adamharvey.name designates 209.85.213.172 as permitted sender) X-PHP-List-Original-Sender: adam@adamharvey.name X-Host-Fingerprint: 209.85.213.172 mail-ig0-f172.google.com Received: from [209.85.213.172] ([209.85.213.172:37984] helo=mail-ig0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 82/49-17766-2A714D45 for ; Thu, 05 Feb 2015 20:23:46 -0500 Received: by mail-ig0-f172.google.com with SMTP id l13so3726379iga.5 for ; Thu, 05 Feb 2015 17:23:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adamharvey.name; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=pfHAtaNSZTK1gi+gE/dqASUtqQgw8+q1H4JSMPUn06Y=; b=Ztj9sxQkCaedUBcUaIFPobtYBPtJly/OXd0wM6hp0KAqO0eN1VlIjPTs+6QXJtq0ds lnOC2HmK7pnx+RQP7ifkphhnntlGTn46/1JMFB/FoDEPNM4bsFnPZ/P/Sd/TSwMbL2b2 +Qehj7cQStAcTyR/mtwMCpBYkOfAXWc9G+XLY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=pfHAtaNSZTK1gi+gE/dqASUtqQgw8+q1H4JSMPUn06Y=; b=XyYNqIWs6AFyhZjzlmD02HaAijPtOHLYrYRDCPbKSXrM1argB4eirf6tLR6ituJd52 YYQ8GBijvfdY878opzWkcQ5N3qLvCSfMcDeV23jeBOGpgrkp9v8itsyNtVyyUVAVHpI1 +5bkwssLj2L3A0N6FKzR9WTOjrXRAfIcMXo5s1yjovs1psbaNCANQ42CCn8gdufmw11F tn+gufmvP/alaSPgsxqMyiLriv7XEzwapimZe8vw7m+ah9PM4YInSmkLCBh0i0FBYUe0 jv8OdRq/VZ0g5tYG+NJh4Whi0B+10B23k/Q6H3oQHHHjQkNC2NihZRh4sfLQg4nF9XPG 5Axg== X-Gm-Message-State: ALoCoQmHgqfVZeAOXmD0flvrG/OJ3D42A4IjMmN/v61tVqc/HnshQPeLtQsji9T1bFzV3pT3f0Xs X-Received: by 10.50.97.41 with SMTP id dx9mr1616384igb.1.1423185816365; Thu, 05 Feb 2015 17:23:36 -0800 (PST) MIME-Version: 1.0 Sender: adam@adamharvey.name Received: by 10.43.112.9 with HTTP; Thu, 5 Feb 2015 17:23:15 -0800 (PST) In-Reply-To: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> Date: Fri, 6 Feb 2015 09:23:15 +0800 X-Google-Sender-Auth: Z3Exm8Y8u1vSumkUisPZZq9bV88 Message-ID: To: Andrea Faulds Cc: PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: aharvey@php.net (Adam Harvey) 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 be= en long enough - I don=E2=80=99t think there needs to be, or will be, much = further discussion. 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. In no particular order, my issues with this RFC: ## The declare switch 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.) 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: * `use strict` is ultimately about code quality =E2=80=94 am I doing someth= ing 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. 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". ## Strong typing 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. 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. 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. ## Caller versus callee 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). ## So what do we do for 7.0? 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: Can I guarantee that my function that expects an integer will really get an integer? 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. Adam