Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:82596 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 82567 invoked from network); 13 Feb 2015 11:05:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Feb 2015 11:05:58 -0000 Authentication-Results: pb1.pair.com smtp.mail=pajousek@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pajousek@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.51 as permitted sender) X-PHP-List-Original-Sender: pajousek@gmail.com X-Host-Fingerprint: 209.85.192.51 mail-qg0-f51.google.com Received: from [209.85.192.51] ([209.85.192.51:56360] helo=mail-qg0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DD/B3-62214-49ADDD45 for ; Fri, 13 Feb 2015 06:05:58 -0500 Received: by mail-qg0-f51.google.com with SMTP id z60so12487293qgd.10 for ; Fri, 13 Feb 2015 03:05:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=Uy1EgxK6fci9tt1t7nRJH5nVMS8/Xl2RxtfZyC92ZAk=; b=UY4hjLcAzHAAqnhI8MnqtbLApR/xniAd0MIckrLVbqbImwdmSx8erWyf3h9AinAW+S SNKKxxheuFTmwkG8zi6vXSOBIg1/5As0mc7RlQhHBuBJmH2YlCDC1Cxkp0+SvykezUSf hdm+QQTOB2UghTTRBkM2a14Jcz2XY1DjRI7T4MsMlWngLRgWVp6oj2sXNUPC4RmQRxDJ hXAMm6GHov4pKK+LW5DqJy7bkpyCeDo2BIbBbqPZX3nuFLHVwiwxV1pqkH7Tkevc1e9d DcvPltPqoFG50GllMLkweJYGAWRUXimEqJCz+HeQJ+sL41lXKvPK1i4TgpTcRZzPx9Y/ D8aw== MIME-Version: 1.0 X-Received: by 10.229.125.133 with SMTP id y5mr8824975qcr.17.1423825553683; Fri, 13 Feb 2015 03:05:53 -0800 (PST) Received: by 10.96.66.201 with HTTP; Fri, 13 Feb 2015 03:05:53 -0800 (PST) In-Reply-To: <342635C4-F0EA-4557-A37F-753E51100402@ajf.me> References: <8703B53E-2C4A-4AC6-95C4-D4F19C6D5221@ajf.me> <54DAF884.7000508@lerdorf.com> <203e611c8e0b03568a868b8d931aec37@mail.gmail.com> <61E01A7C-C5C8-447F-A8FA-E12A18E847CA@ajf.me> <85D76C91-9A9E-459B-847A-619AA21B9262@ajf.me> <342635C4-F0EA-4557-A37F-753E51100402@ajf.me> Date: Fri, 13 Feb 2015 12:05:53 +0100 Message-ID: To: Andrea Faulds Cc: "guilhermeblanco@gmail.com" , Zeev Suraski , Rasmus Lerdorf , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Scalar Type Hints From: pajousek@gmail.com (=?UTF-8?Q?Pavel_Kou=C5=99il?=) On Thu, Feb 12, 2015 at 3:31 PM, Andrea Faulds wrote: > Hi Pavel, > >> On 12 Feb 2015, at 13:48, Pavel Kou=C5=99il wrote: >> >> C# does have dynamic typing. > > No it doesn=E2=80=99t, it=E2=80=99s a statically-typed language. I don=E2= =80=99t understand why you say it has dynamic typing - there is some limite= d dynamism in parts, but I don=E2=80=99t think it affects what we=E2=80=99r= e talking about. Dynamic typing and polymorphism aren=E2=80=99t the same. > I never said dynamic typing and polymorphism are the same, or did I? Also, C# has type "dynamic", which allows for usage of dynamic typing in C# (technically, under the hood, it is an System.Object type without the need for casting, IIRC). >> I just don't believe that method overloading would suddenly make >> everyone write poor programs. > > Maybe not, but all the facilities needed to make good programs are alread= y there. Overloading would only really be useful for writing bad programs, = because all the good things it enables are already supported by PHP. > >> It brings cleaner declarations of methods and functions. > > Only slightly. A switch() (or better, a pattern match, were we to add tha= t) can do the same job and it=E2=80=99s not that much less clean. > Actually, I wouldn't mind having both pattern matching and method overloading in PHP. I'd say that both of them have their use, and not everywhere you'd use pattern matching you'd use method overloading and vice versa. function foo(Foo $a) {} function foo(Foo $a, Bar $b) {} function foo(Foo $a, Baz $c) {} This is much much more cleaner than doing: /** * description of what it does depending if you pass Bar or Baz or null */ function foo(Foo $a, $b =3D null) {} In pattern matching it could be done with, let's say: foo $a, $b | $b instanceof Bar =3D {} | $c instanceof Baz =3D {} Which is IMHO as unclean as using ifs statements inside the method. :( And at the same time, I don't see how you could do this via method overload= ing: signum x | x < 0 =3D -1 | x > 1 =3D 1 | x =3D=3D 0 =3D 0 I hope this example is correct, it's been a while since I used Haskell. >> Also, it >> brings the possibility of having operator overloading in user classes >> someday in the future (yes, this can be abused as well, but it also >> has legitimate use cases - like class for representing Money and being >> able to do +, - , / or * operations on them). > > Overloading isn=E2=80=99t necessary for operator overloading. > It isn't, but both would be nice. >> Is the option of omiting >> type hints and having optional parameters really a good enough >> replacement for method overloading polymorphism for you? Because for >> me, it unfortunately is not. :( > > Well, yes. PHP is dynamically-typed, this can happen, whether you=E2=80= =99re using strict or weak typing. Your only way to guard against it here i= s to do proper testing. Well, if we added a numeric type hint, your IDE cou= ld catch this error for you, actually. > > Anyway, the same thing can happen for float->int conversions *with* weak = typing, as we disallow certain conversions (PHP_INT_MIN > $x, PHP_INT_MAX = < $x, !isfinite($x), isnan($x)). > > Also, even though PHP does allow most float->int conversions with weak ty= ping, it doesn=E2=80=99t mean they=E2=80=99re a good idea. Silently losing = the fractional part is probably not what you want. > As I stated few times already, I find float -> int a bad idea (even in weak mode). That's at least something we can agree on I guess? :) Regards Pavel Kouril