Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81832 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62558 invoked from network); 4 Feb 2015 18:41:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 4 Feb 2015 18:41:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=narf@devilix.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=narf@devilix.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain devilix.net designates 209.85.218.43 as permitted sender) X-PHP-List-Original-Sender: narf@devilix.net X-Host-Fingerprint: 209.85.218.43 mail-oi0-f43.google.com Received: from [209.85.218.43] ([209.85.218.43:48613] helo=mail-oi0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id FF/F3-40930-1D762D45 for ; Wed, 04 Feb 2015 13:41:22 -0500 Received: by mail-oi0-f43.google.com with SMTP id z81so2717128oif.2 for ; Wed, 04 Feb 2015 10:41:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=devilix.net; s=google; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=s/qMcjb4ls3IKK5BuVsWhE0e55wrldwmX/B8C1pq20Q=; b=Nl/Y+CfQDzyCFqrCrIzOjExfTU2nZG+CXj7fHJyRg5hskOzV7Pq9wYwJqDCZNHqyF0 TuXOTZSDwRLVYYstBGbiHKqdrknhulK6RcA4Glt4tf2bb8sXhnQ+CLjt7NalZ3ST4XBJ n9w8p5agtUEzFMmM/nDSmJW+w+XISr3gNWNwM= 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:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=s/qMcjb4ls3IKK5BuVsWhE0e55wrldwmX/B8C1pq20Q=; b=TQ7WbALyWDRQutznXDPLZ0eb3l/ppy3SmQn3G0ArX6o5HyimPCHN4Lww3l4Xa1uaMR Lo/qwoU4ksxZiQqMKpIQD8anUZn/lqpbV5DwBSXKslqYSDqLB8xpKJjzQYjEZen33VBu xoewMhGOejPq8w9sFEPjZpbfMvY7onRpkM3t4TntR5vwu3RuMfRCTccwSE5hvef+TGrU FdtZ1FkGYEJZRn2Dey/wPsFcpcbGIlv35AVWYefYUyD4R+3IDR8K925ADbpYOq/hdxbN wLwNPzA2BOK/hkwWYxpZGthiTln5HvCMmqS2qPwg4cHCBrY5GOfjUTgZJJrwVdjn8JlC 0AQQ== X-Gm-Message-State: ALoCoQku5/G0TyomXQ9ATloA0RWNBwRr0h33KMOwgooSIFc+1OyZTMYLtifHSwz9CrLbEA+C1rEy MIME-Version: 1.0 X-Received: by 10.60.70.141 with SMTP id m13mr19966094oeu.86.1423075278345; Wed, 04 Feb 2015 10:41:18 -0800 (PST) Received: by 10.202.214.205 with HTTP; Wed, 4 Feb 2015 10:41:18 -0800 (PST) In-Reply-To: <85CB3199-8D44-4D34-9212-6E18D6BD7B73@ajf.me> References: <85CB3199-8D44-4D34-9212-6E18D6BD7B73@ajf.me> Date: Wed, 4 Feb 2015 20:41:18 +0200 Message-ID: To: Andrea Faulds Cc: Florian Margaine , Leigh , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] What do we need strict scalar type hints for? From: narf@devilix.net (Andrey Andreev) Hi Andrea, On Wed, Feb 4, 2015 at 8:21 PM, Andrea Faulds wrote: > Hi again, > >> On 4 Feb 2015, at 11:15, Andrey Andreev wrote: >> >> On Wed, Feb 4, 2015 at 1:02 PM, Florian Margaine = wrote: >>> Hi Leigh, >>> >>> Le 4 f=C3=A9vr. 2015 11:50, "Leigh" a =C3=A9crit : >>>> >>>> What was wrong with: >>>> >>>> function x(int $y, string $z) { // strict >>>> function x((int) $y, (string) $z) { // casting >>>> >>>> This was the best suggestion I've seen that covers the requirements of >>>> both camps, and is still very clear how data is going to be handled. >>>> >>>> Authors who want their APIs to adhered to strictly can do that, >>>> authors who want to accept anything and have it end up as their >>>> desired type can do that too. >>> >>> Because it is then the callee who decides, not the caller, whether or n= ot >>> he wants strict typing. >>> >> >> ... and apparently, this is the root of all evil. :) > > It=E2=80=99s not =E2=80=9Cthe root of all evil". But the two-syntax appro= ach has disadvantages I=E2=80=99ve elaborated numerous times. > > It shifts the choice to the callee, not the caller. This means existing a= pplications are broken if strict hints are added to existing libraries. It = means that programmers will have to deal with two different systems, simult= aneously, in the same file or function or method, because one API uses (int= ) and the other uses int. It means that if the API author decides to have w= eak types, you are prevented by the language from having the benefits of st= rict typing, even if you want them. It also has a syntax issue: (int) looks= like an explicit cast, yet what is usually proposed doesn=E2=80=99t someth= ing similar. There=E2=80=99s also the consistency issue in that we=E2=80=99= d have to support real for consistency with (real), since T_DOUBLE_CAST is = a token. It means that internal functions could now also use strict hints -= or if they can=E2=80=99t, we have a consistency issue. It means beginners,= and people who don=E2=80=99t like strict types, now have to deal with stri= ct types in their code, despite PHP always having been a weakly-typed, begi= nner-friendly language. And so on, and so forth. > > The current RFC deliberately does not propose this because I think it cau= ses more problems then it solves. > >> I am baffled by how the two-syntaxes suggestion is always so easily >> dismissed by that argument. I'd argue that most people who support the >> current proposal don't fully understand what declare(strict_type=3D1) >> really does. > > Well, *I* understand what it does. That's an own goal (in football/soccer terms), you know. ;) > I=E2=80=99ve used it. It worked really, fantastically well=E2=80=A6 bette= r than I expected it to. It provided benefits that the two-syntax suggestio= n wouldn=E2=80=99t have. It provided benefits that just strict hints wouldn= =E2=80=99t have. It provided benefits that just weak hints wouldn=E2=80=99t= have. > >> As I've previously said - putting the caller in control >> (and really the caller, not in a per-file context) makes it a >> debugging tool, not support for strict typing. > > What=E2=80=99s the difference between =E2=80=9Cper-file=E2=80=9D and =E2= =80=9Creally the caller=E2=80=9D? The RFC *does* allow you to use declare()= blocks if you really want to. > > Also, type hints are mostly a debugging tool anyway. They=E2=80=99re a to= ol for catching errors early, and to enable better documentation. That=E2= =80=99s all that they do. > Yeah, you've said that numerous times ... almost as much as I have disagreed with your arguments. I didn't want to turn this thread into a re-iteration of the RFC discussion one. I'm just completely surprised how relentlessly all suggestions about two syntaxes have been waved off by a callee vs caller argument like it's a golden rule or something ... it's not, you just don't like the other approach. Cheers, Andrey.