Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125093 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 2B5D11A00BD for ; Wed, 21 Aug 2024 18:24:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724264800; bh=spFBJ1t3s9z1C6q7C74Sf6/H/7od9Ib0PH8hU06M5YI=; h=Subject:From:In-Reply-To:Date:Cc:References:To:From; b=S/Hovha7/od5tlBnC7Bg8AZXhE1RQTjZcCcC9h2LmpVu8GBGNUDU1iIX4am5fXb7u GQok+73XPIzsE7X/XZOl2pAHwlUBwGCYYKH07y3hxtX+MAho7W50Eak+Z7QKHAdYX2 wssluqbcK34zDywriqcn3DTY5E6rnJhVcayabZhPFCwoDyrSv2JwmNXQ4eN6camTUd /E+rFN8dx8FJP2AOe3LW66xr/GcmsqeFTHiIMF+baRKJgx4GZHdpC+ysCU/a0uaNpZ QicuskA/w043dRB7fcCU+PMEkMDHlSR4bOUXlRQpYheluQBpTvoZUMWhTBeSrYKr0b bSN8r8xZP3v2A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 15E8A180072 for ; Wed, 21 Aug 2024 18:26:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DMARC_MISSING,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-yb1-f178.google.com (mail-yb1-f178.google.com [209.85.219.178]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 21 Aug 2024 18:26:39 +0000 (UTC) Received: by mail-yb1-f178.google.com with SMTP id 3f1490d57ef6-e1661dcbc2fso34801276.0 for ; Wed, 21 Aug 2024 11:24:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20230601.gappssmtp.com; s=20230601; t=1724264689; x=1724869489; darn=lists.php.net; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=isXDh1gvWHDS9VLkh9TJaWlz+K+LaTiVLUhytRYbue0=; b=EU80nR1I9f3/6oevRENplxX51UM0ieV4kSOcIpg0OU6P/XNVA3Ak7bBm1So/3MTsCz 5Kh2+9ch7/SRUZ11FAtDY78S0H949j0JXckeL9qUsg6UP5nl+ZvHqUD3vPNAO9vRGcqb oGit/j0krbRAIwNz8UudD6muvAB7JPoGezqXgdj3xHdr54QNeEGI1Rshihi8LF65ZveV GGEm7kKVqOZZ5m71pefS41KnVzCdNaczpqajD6H0/yDHHya7Lrp/5kqGTWJ5rTuvs8ZV 6zWFQEjLh2fyS1lZdFIKP/gTSQ8+X6WeyRtcKdDgNOdpZ7oKx/tzkLxDoA/Q/ufklym8 O88w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724264689; x=1724869489; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=isXDh1gvWHDS9VLkh9TJaWlz+K+LaTiVLUhytRYbue0=; b=AYAmzUWxcahA46WRIe8pzPZB/oEBhQ/R3Lc9GzH/6FnGFk+xOn91Qr66AtVbgQP2L8 vZbLO2+Gzm5/0iJnTYDX09Lnm4kCJACK8G14iPEuPHhsA1C0aP6dvEqdYrxd8HBvrey0 U+ydHWS5sc+8RlwJCkNFSC+RYmpbftGebAHnxfl80RBvReGuRPvSuW0xbbhE7Z/Kkmmo 7Vw0vdmhoNpzYnOQmo1FfHL2pu1JZQdvNy19pMrn+KzxPopqK7wvCybiHCUlhjJUHJWv tx1Alc2nPVTk0x4ezSCImpmdVFcU1N39MOVtSLTt/659qiDtPICt+0+hilc2w6AfmunV +u4A== X-Gm-Message-State: AOJu0YwQsARfZFMWM1y4/Q98szkQr/WxkPgSN9Lt90l+xHpk4cBp/S/U 8I4p55HI49N8JbOgJiczCR1YH/sJ4u2PnnF/aVQDjZjWkfBAu9g//XyTcVPN6jH9Dq8q6B2C90p X130= X-Google-Smtp-Source: AGHT+IF9ki3g7UnPvCs5FfYUM0z4GM3EYnlvh33n/m5c+fGNmhjmEb/9lg4qiGw+5cKOsnmVXeS0wg== X-Received: by 2002:a05:6902:1b8f:b0:e13:eba5:4073 with SMTP id 3f1490d57ef6-e166642f699mr2879079276.30.1724264688553; Wed, 21 Aug 2024 11:24:48 -0700 (PDT) Received: from smtpclient.apple (c-98-252-216-111.hsd1.ga.comcast.net. [98.252.216.111]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6af9a86a861sm23876767b3.73.2024.08.21.11.24.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Aug 2024 11:24:48 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.8\)) Subject: Re: [PHP-DEV] State of Generics and Collections In-Reply-To: Date: Wed, 21 Aug 2024 14:24:43 -0400 Cc: PHP Developers Mailing List Content-Transfer-Encoding: quoted-printable Message-ID: References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> To: Arnaud Le Blanc X-Mailer: Apple Mail (2.3696.120.41.1.8) From: mike@newclarity.net (Mike Schinkel) > On Aug 20, 2024, at 9:44 AM, Arnaud Le Blanc = wrote: >=20 > Hi Mike, >=20 > On Tue, Aug 20, 2024 at 2:45=E2=80=AFAM Mike Schinkel = wrote: >> It seems Java-style Generics are viewed as the proper archetype for = Generics in PHP? I would challenge the wisdom of taking that road = considering how different the compilers and runtimes are between the = Java and PHP. PHP should seek out solutions that are a perfect fit for = its nature and not pursue parity with Java. >=20 >> As PHP is primarily a web development language =E2=80=94 vs. a = systems language like C or Rust, or an enterprise application language = like Java or C# =E2=80=94 reducing code complexity for reading and = understanding is a very important attribute of the language. >=20 >> PHP is also a unique language and novel solutions benefit a unique = language. PHP should pursue solutions that result in less complex code = even if not found in other languages. Your collections idea is novel =E2=80= =94 which is great =E2=80=94 but there are probably even more novel = solutions to address other needs vs. going full-on with Java-style = generics. >=20 >> Consider if adding type aliases; or augmenting, enhancing, or even = merging classes, interfaces, and/or traits to address the needs = Java-style generics would otherwise provide. I would work on some = examples but I think you are more likely to adopt the features you come = up with on your own. >=20 > Part of the appeal for Java/C#/Kotlin-like generics is that they are > well understood and their usefulness is not to be proven.=20 Yes, they are well understood by programmers who develop in a = significantly more complex language. So while I acknowledge that appeal, = I think the complexity provides benefit for most PHP developers. > Also they fit well with the object-oriented aspect of the language,=20 Even more importantly, PHP is not Java and what works for a compiled and = strongly typed language does not necessarily work for a interpreted = language with looser typing and where only one file can be seen by the = compiler at a time. > and many PHP projects already use them via PHPStan/Psalm. As an aside, it is an interesting data point that such as small percent = of PHP developers actually use those tools.=20 Could it be because of their complexity? I cannot say for certain that = is why, but it surely is a factor to ponder. > More experimental alternatives would be more risky. Fair point > I would be interested to see suggestions or examples, however. Two examples were already shown and/or mentioned: the collections class = and automatic interface implementation based on structural typing. =20 I am sure they are more, and if I am able to identify any as the topic = is discussed I will bring them up. >> As for type-erasure, I am on the fence, but I find the proposed "how" = problematic. >> I can see wanting some code to be type-checked and other code not, = but I think more often developers would want code type-checked during = development and testing but not for staging or production. And if the = switch for that behavior is in every file that means modifying every = file during deployment. IMO that is just a non-starter. >=20 > The reason for this "how" is that type checking is also coercing, so > disabling it "from the outside" may break a program that's not > designed for that. AFAIK if you are using type checking then the code is never correct if = the types do not match, the errors just may go unreported. Thus I do not = see how the code that uses code with types could not be designed for = code with types; disabling if from the outside does not change that.=20 Disabling type checking is not like changing the syntax that is allowed = by strict mode, AFAIK. > type checking is also coercing However, I do not understand your claim here. Is there some form of = typing that would modify code behavior if the types were erased? Would = allowing that even make sense? Can you give an example of this? > That's why this is something that should be enabled > on a per-file basis, and can probably not be switched on/off depending > on the environment. I reserve my opinion on this awaiting your example(s). >> P.S. Also consider offering the ability for a function or class = method to "type" a parameter or variable based on an interface and then = allow values that satisfy that interface structurally[1] but not = necessarily require the class to explicitly implement the interface. >=20 > Unfortunately, I believe that structural types would be very expensive > to implement at runtime. Static analysers could support this, however > (PHPStan/Psalm support some structural types already). But would it really be too expensive? Has anyone ever pursued = considering it, or just dismissed it summarily? Seems to me it could = handled rather inexpensively with bitmaps. -Mike