Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:125070 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 01E4B1A00BD for ; Tue, 20 Aug 2024 13:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1724161605; bh=6e/MbKmeXs5ex+xw7Sh2ReKJz/0BA11xnM4IJUsJKtA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=M0qUobfN/FlAVem9WvEw/6+E5BE0wqvJUuZEtDGXh/wKpb7qM0HIdcrQHHTA4Zc2n XZHjnRm+xdjWexnOFei/BBSKUjkQR8DG2Vc9FgYQ7GvtE4cL27X+vveAZYbbtwjjxI 0qcX8AQEsFV6gZF1MD034zOrdOZ1E6a1B3yp4LZbpZYj9b6k+6fcI6EDSbX5FFoM/U 2heuWjn6ljVZFWeo4xcbSbxgoLmzpT1bqPSjw/M87KhMgQs4bLa6AGnIZyVUrZCTwQ Wjrh5ohIWZfHS/d1iSjMYsdHHbdd9CEI9iuEGsnfbvwCyu2J+n/am1uDR9YbIF48fD O5c/4ZVrzXipg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 48FB7180062 for ; Tue, 20 Aug 2024 13:46:44 +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.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (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 ; Tue, 20 Aug 2024 13:46:43 +0000 (UTC) Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-533462b9428so236268e87.3 for ; Tue, 20 Aug 2024 06:44:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724161493; x=1724766293; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=1kBRWdnijgRdTCyC5tenGcFd3qh+y9Exq9FlaXA9fQY=; b=NHQ4pDgA8YQEl2T+NBi171tFHpN7IlSxzea24ct0xImzdf3MnXQ1R6yzBmtknSakJ0 l0bsRcFrjj5XZhp+IEwOZ9Vq/nYEYobXcBjkbupg2au5h5a1aLF2GRrgoka+NNfMBbsz UKpTbpU9iyMKX0cD6Z+TadsiMnBdn8sKLF9HhG5oqf4rO26Teu4Ke7Tip61y5IbCZ3BW HVx9iI3dogmDtYxgV98f7IHoAJj7XGHwKwWHSOkluncJXunJvyhWh5y7d2BbRQ/vrKHf 9SqrgQs5x10ufdsj+UuVVDwgsL/qKnBDFDl7zAF4mxWxi3uWtQIFMlZZ/1gzk7Hg8NFv g/eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724161493; x=1724766293; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1kBRWdnijgRdTCyC5tenGcFd3qh+y9Exq9FlaXA9fQY=; b=aNXvidVy4J5DUORfJsRgVPX5kcicgj2Kc/TI1a/QogidcEfegjWX/Dg0QAnroMM21o joMwS3VCmQ3Fz96dRnIZM1tn99qslN1IoTs77IH1cEuL8EkFJOAXP6ZCw/5Us0tUzTsB LeCOhusSJAZ3CbVGr2ug0nsz/iWNmIqidFN7k9thdgWs4jLS9bKz1O7Fe0PxDsHUMyKi Ag6qwSsRUbjXhNLYCIuejPgR/punUOxsCiE5uPTXwDI+u7886op6FvNDfs2Eis/tX44s aI6fvvFXvJ+l8l+5VSCYqbUnNwWBpdNnAiw27dsZqH5HTHvC3/1AIQK42m0oJPYpu827 5G9Q== X-Forwarded-Encrypted: i=1; AJvYcCVM5ttOS5hoOU+OzWzjKK58ZTRTqMikavA5JIgFYV7MspXrLBOtuko1NLdH8yaGkse6i5w81C0TT8hQVHmIDmt+ylo8Z82+rQ== X-Gm-Message-State: AOJu0YwHor2poIRUtBnIl2YX2C1WxfDMDq9kbG17354oTKEKsu7CP6PX awDoEG5F4kRM1dBqSAd+uUzMLCgxdR7d+/zP7/VIZ1E2whxfNZqcqD7p/CzkY/1YN4+9hzclk9Y sVaYRE1Rg1EP572dFzMpNfIBjUiDYOEXm X-Google-Smtp-Source: AGHT+IF10n6HIEPLefZylzlDMWkfTXEIRRwI1gXRg1dv2wkZVhp/GPEs4ymB8tplS8zofbRjgfHx9WCfQP5DWQjLPOo= X-Received: by 2002:a05:6512:3989:b0:52c:a20e:4da4 with SMTP id 2adb3069b0e04-5331c6e51f3mr11366456e87.57.1724161492445; Tue, 20 Aug 2024 06:44:52 -0700 (PDT) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <1b59392a-68cb-36eb-0fef-977ac7113520@php.net> In-Reply-To: Date: Tue, 20 Aug 2024 15:44:41 +0200 Message-ID: Subject: Re: [PHP-DEV] State of Generics and Collections To: Mike Schinkel Cc: Derick Rethans , PHP Developers Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: arnaud.lb@gmail.com (Arnaud Le Blanc) Hi Mike, 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 Gener= ics in PHP? I would challenge the wisdom of taking that road considering h= ow 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 pur= sue parity with Java. > As PHP is primarily a web development language =E2=80=94 vs. a systems la= nguage 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 ver= y important attribute of the language. > PHP is also a unique language and novel solutions benefit a unique langua= ge. PHP should pursue solutions that result in less complex code even if no= t 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 addr= ess other needs vs. going full-on with Java-style generics. > Consider if adding type aliases; or augmenting, enhancing, or even mergin= g classes, interfaces, and/or traits to address the needs Java-style generi= cs would otherwise provide. I would work on some examples but I think you a= re more likely to adopt the features you come up with on your own. Part of the appeal for Java/C#/Kotlin-like generics is that they are well understood and their usefulness is not to be proven. Also they fit well with the object-oriented aspect of the language, and many PHP projects already use them via PHPStan/Psalm. More experimental alternatives would be more risky. I would be interested to see suggestions or examples, however. > As for type-erasure, I am on the fence, but I find the proposed "how" pro= blematic. > 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. 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. 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. > 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 th= e class to explicitly implement the interface. 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). Best Regards, Arnaud