Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124130 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 0C5401A009C for ; Mon, 1 Jul 2024 06:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719815712; bh=y0fBkEoh5ZZzJd3ZfpgTy+t0mYQpgKnQ6rMdmXxQj04=; h=In-Reply-To:References:Date:From:To:Subject:From; b=Y+eKrEF+BUnt2Iqdm65xNAc0YZ1131Hwen5letldBMo2FlGv07Ct5aTqmgyUNKoa+ mjEx9WkU2hwEQDWmB0UcUdVUYOO0G9UN8J+xorIc+mQd0gB34ZV69nIM4fv1B3k/Cm gAe/Lxo+YqceHtg365CezWEbWmGrRwszMWaD5Bz/6hHWQgplwsGW2rydNIlDflFm2G 59tzDNkLFq7qQIumtegRw0/NdD8mTrcNXFze5ICmtkVDxQbBg2ZQ7gtGwkGYMNw2p7 1FyYo8vVIef/yua8AgWuwHQKneOdWRial/M62pRzRHqwj9G6WaiT6ONDDthCjRmxXr /11aPaoiMcOdw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 0ADB718059C for ; Mon, 1 Jul 2024 06:35:11 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,HTML_MESSAGE, RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) X-Envelope-From: Received: from fout6-smtp.messagingengine.com (fout6-smtp.messagingengine.com [103.168.172.149]) (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 ; Mon, 1 Jul 2024 06:35:10 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id AC5421380229 for ; Mon, 1 Jul 2024 02:33:49 -0400 (EDT) Received: from imap49 ([10.202.2.99]) by compute1.internal (MEProxy); Mon, 01 Jul 2024 02:33:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bottled.codes; h=cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1719815629; x=1719902029; bh=HjNlG+wbvh Q3pjYxh99Ww28qwDdnyFy1Ta5qlgk+IK4=; b=KFIIvtXhIPieU05fC3vjFPFpYG TEW9R/jSv7j/y/FIVGpiXCuieFecU5Kqn7EzCpkIAg19MteECGGONTGEsy8UQ6Ut mSNhtRrCNvUAisp/nyPa0UagS/LeEispmizLOP8/PNNA33VUf19WzVcMKmknnMUr niHVH6biTMGp1anLAYA+wrk7xs3CxWPRqax7cN/joncqiMrbcmv+1VJi9yuMOt0Z fg0u3KLxmKUqR//DtMisKznTmLL9T7s1ouWQtsssqKbmIOAGmB5NgCEp5Dw6aR1M 6Plxozr1oTtUsSprIYxNVL5N5+JsDySzZP2DBHuEXaMFZl5/7cu2eHf30z5Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1719815629; x=1719902029; bh=HjNlG+wbvhQ3pjYxh99Ww28qwDdn yFy1Ta5qlgk+IK4=; b=CSUNNTbtpzaghWWH00o738cTrKX/5CzEC512pV2Yz7lK pK2eFTrnA2TcZZ3fnRX8Son+ZkOPM/MI107WiX/v+NG3mlJyFRNZn5IVptD0AWPu sNU0cIr6F9ERIP9tlTrXPBTsoJPOgB0mNEZ5xxSsg25RkQVwhP546ezrLlFwGTUu X4G6swXLh66zitOpAWB44j3LmlW+bPiQlnMTb4qgVMbspCycwcz4CiAxF7HqkijW oGpKcs+xlsIKKqcTZRVA75Xo8nnJVCCkNV+FJkVpB76t4yjyutuz7fl4U/xVWxlV kkeT5dg62MABSOgFCB31QPoJkqHfz9RcYAb4XQaPpQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddruddvgddutdekucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefofgggkfgjfhffhffvufgtsegrtd erreerreejnecuhfhrohhmpedftfhosgcunfgrnhguvghrshdfuceorhhosgessghothht lhgvugdrtghouggvsheqnecuggftrfgrthhtvghrnhephfevvdevffduvedutdelgfeuhf fhleekfeetvdekvddutdehieffteetudevvdejnecuffhomhgrihhnpehgihhthhhusgdr tghomhdpphhhphdrnhgvthenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehrohgssegsohhtthhlvggurdgtohguvghs X-ME-Proxy: Feedback-ID: ifab94697:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 31F5615A0092; Mon, 1 Jul 2024 02:33:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-566-g3812ddbbc-fm-20240627.001-g3812ddbb Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net MIME-Version: 1.0 Message-ID: In-Reply-To: <4996ae09-e5eb-4a8b-90e2-7461805c4cb7@app.fastmail.com> References: <4ECBB519-B129-426F-93AE-33738A1ABA06@miles.systems> <4996ae09-e5eb-4a8b-90e2-7461805c4cb7@app.fastmail.com> Date: Mon, 01 Jul 2024 08:33:22 +0200 To: internals@lists.php.net Subject: Re: [PHP-DEV] [Initial Feedback] Typed Arrays Content-Type: multipart/alternative; boundary=210e74bf5cbe4d088bc72173a306939d From: rob@bottled.codes ("Rob Landers") --210e74bf5cbe4d088bc72173a306939d Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable On Mon, Jul 1, 2024, at 02:59, Larry Garfield wrote: > On Sun, Jun 30, 2024, at 11:13 AM, Micha=C5=82 Marcin Brzuchalski wrot= e: > > Hi Richard, > > > > czw., 27 cze 2024, 22:33 u=C5=BCytkownik Richard Miles=20 > > napisa=C5=82: > >>=20 > >> > I worked with Joe Watkins to do a proof-of-concept for generic tr= aits. > >> > It's a bit old since it's from 2017, but could be a useful starti= ng > >> > point if you are serious about pursuing this idea: > >> >=20 > >> > https://github.com/php/php-src/compare/master...morrisonlevi:php-= src:parameterized_traits > >>=20 > >>=20 > >> I=E2=80=99m also interested in this; it will help see branches like= these. > >> Did you ever get the POC working? What did you feel like was the bi= ggest hurdle? > > > > There even was an RFC in voting which Joe implemented and it address= es=20 > > nearly what is discussed it this thread https://wiki.php.net/rfc/arr= ayof > > > > I must admit that the collection proposal is bit too complex t= o=20 > > address such tiny but powerfully in my opinion functionality which i= s=20 > > typed array. What Derick showed looks more like generic collection a= nd=20 > > such require declaring it's type. In my opinion this is way too mush=20 > > hassle to declare as many collection types as many usages in=20 > > application. Also two collection types with the same collection item=20 > > type will not be compatible from type perspective. While typed array=20 > > seems much more clear and compatible in all places where typed array= is=20 > > needed without declaring separate type for each usage. > > > > If I were to choose between typed-array and collection like Derick=20 > > showed a little bit I'd choose typed arrays definitely as a first=20 > > feature to be merged into PHP. > > > > Cheers, > > Micha=C5=82 Marcin Brzuchalski >=20 > Contextual point: Nearly every other major language at this point that= has a meaningful standard library has gone with a three-separate-object= approach (Seq, Set, Dict, called various things). At least Python, Jav= ascript, Rust, Kotlin, and Swift, in my research. (Go doesn't, but Go a= voids having features by design.) And AFAIK *every* language except PHP= and Lua separates sequences from dictionaries. Typed arrays will not f= ull resolve the seq vs dict problem, which is arguably PHP's original si= n. And there's a lot of weird issues to resolve around what the syntax = could even be, since PHP has untyped variables. >=20 > The custom collection syntax Derick has been working on is a second-be= st alternative to generics, essentially. It is less ergonomic, no quest= ion, but can also be implemented without generics, and so is about 5x ea= sier to do. If we could get native generics, then I think everyone invo= lved agrees building collections off of that -- in essentially the same = way as every language I mentioned above --- would be preferable to a cus= tom one-off syntax. >=20 > --Larry Garfield >=20 Just to add, the current implementation of arrays allows for using them = as =E2=80=9Csparse sequences=E2=80=9D which is pretty unique to PHP. I=E2= =80=99ve personally relied on this many times in my career (where we are= only interested in non-zero elements) for scheduling, efficient matrice= s, and recommendation systems. It=E2=80=99s another type worth consideri= ng in the list you provided, assuming that Seq would strictly be a seque= nce.=20 =E2=80=94 Rob --210e74bf5cbe4d088bc72173a306939d Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
On Mon, Jul 1, = 2024, at 02:59, Larry Garfield wrote:
On Sun, Jun 30, 2024, at 11:13 AM, Micha=C5=82= Marcin Brzuchalski wrote:
> Hi Richard,
= >
> czw., 27 cze 2024, 22:33 u=C5=BCytkownik Richard= Miles 
> <richard@miles.systems> napisa=C5=82:
>>&= nbsp;
>> > I worked with Joe Watkins to do a proo= f-of-concept for generic traits.
>> > It's a bit = old since it's from 2017, but could be a useful starting
&= gt;> > point if you are serious about pursuing this idea:
>> > 
>> 
<= /div>
>> 
>> I=E2=80=99m also interes= ted in this; it will help see branches like these.
>>= ; Did you ever get the POC working? What did you feel like was the bigge= st hurdle?
>
> There even was an RFC i= n voting which Joe implemented and it addresses 
>= nearly what is discussed it this thread https://wiki.php.net/rfc/arrayof
&g= t;
> I must admit that the collection<Dict> propo= sal is bit too complex to 
> address such tiny but= powerfully in my opinion functionality which is 
>= ; typed array. What Derick showed looks more like generic collection and=  
> such require declaring it's type. In my opinio= n this is way too mush 
> hassle to declare as man= y collection types as many usages in 
> applicatio= n. Also two collection types with the same collection item 
> type will not be compatible from type perspective. While typ= ed array 
> seems much more clear and compatible i= n all places where typed array is 
> needed withou= t declaring separate type for each usage.
>
> If I were to choose between typed-array and collection like Deri= ck 
> showed a little bit I'd choose typed arrays = definitely as a first 
> feature to be merged into= PHP.
>
> Cheers,
> M= icha=C5=82 Marcin Brzuchalski

Contextual po= int: Nearly every other major language at this point that has a meaningf= ul standard library has gone with a three-separate-object approach (Seq,= Set, Dict, called various things).  At least Python, Javascript, R= ust, Kotlin, and Swift, in my research.  (Go doesn't, but Go avoids= having features by design.)  And AFAIK *every* language except PHP= and Lua separates sequences from dictionaries.  Typed arrays will = not full resolve the seq vs dict problem, which is arguably PHP's origin= al sin.  And there's a lot of weird issues to resolve around what t= he syntax could even be, since PHP has untyped variables.
=
The custom collection syntax Derick has been working on i= s a second-best alternative to generics, essentially.  It is less e= rgonomic, no question, but can also be implemented without generics, and= so is about 5x easier to do.  If we could get native generics, the= n I think everyone involved agrees building collections off of that -- i= n essentially the same way as every language I mentioned above --- would= be preferable to a custom one-off syntax.

= --Larry Garfield


Just to add, the current implementation of arrays allows for using the= m as =E2=80=9Csparse sequences=E2=80=9D which is pretty unique to PHP. &= nbsp;I=E2=80=99ve personally relied on this many times in my career (whe= re we are only interested in non-zero elements) for scheduling, efficien= t matrices, and recommendation systems. It=E2=80=99s another type worth = considering in the list you provided, assuming that Seq would strictly b= e a sequence. 

=E2= =80=94 Rob
--210e74bf5cbe4d088bc72173a306939d--