Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:124136 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 0F61A1A009C for ; Mon, 1 Jul 2024 12:37:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1719837548; bh=VGWptQfUi0VSwDR7aMEW893Aqy5tLovWrIPPNaR7mK8=; h=In-Reply-To:References:Date:From:To:Subject:From; b=dhuRCXhYtafbpnQ5F8V/RYCG2l+18peTQawXWQr0Gub9gUEbsFmzwhuNmaotVwN1v WXxJiSDXwJFHJnS5fgjij+S8nRE+5IemKOzQY8k1nvw4q7G4iFpvous5wZ2qrH59Tz EX1YD+YTGJU4/9LiCK+LLzh26yx9nQYF6IQgBoMgZyhrtVfR4sRn/FpN0ksTFAqfzQ bZBu8QIvkrnJVPnoUVLYCm/RolauPXffOosZ8FZlmOwXJdaEYXFJeaYl2nB+rJ055/ h3/D54SZovlhsZva8WyqLCvWbDpbubtCdGlmXMAzTmxZGOGsh40iXp7Sj+dxotyH6+ 5OsUASr+IyWiQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 5B5E318085E for ; Mon, 1 Jul 2024 12:39:07 +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,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE,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 wfhigh7-smtp.messagingengine.com (wfhigh7-smtp.messagingengine.com [64.147.123.158]) (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 12:39:06 +0000 (UTC) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.west.internal (Postfix) with ESMTP id E2DCF18000A2 for ; Mon, 1 Jul 2024 08:37:44 -0400 (EDT) Received: from imap50 ([10.202.2.100]) by compute1.internal (MEProxy); Mon, 01 Jul 2024 08:37:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding: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=fm2; t=1719837464; x=1719923864; bh=UJgYYpsKjVV24R7jP8bcx qlCmASOG+osEX/ItL3FVj0=; b=YKVVMeLdfUKth4G9Lmd7J/+thud3LJJGDI8xf uMjud7krrVIHJ7VEhTY3EOKpsWYYSgK7VF2sS+FcGoXhWrAPsOUQQYJcEyk2Om8n AZZByLD8KJRNsvEnj+IAbNbkG3O0eIZYwnd0a8VEMDOxfBiH855304B9DBhKLcYL k9D71De8qXAmyodV3ASzSSvPnwbWdpUDgAsqBLasEp16JxtKsvPnFTHLZIt5D8yV 08eSSNH+iO96txNGTFiiwQTIx57PCAtbokvm6ckM9wSvCWNdWASD7QFRVaC6oZ5Y 9JB9+hYFn4DzoEC55OGwOuZBWMYyZUcwfz3kVQLdcV42/ucmg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding: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=1719837464; x= 1719923864; bh=UJgYYpsKjVV24R7jP8bcxqlCmASOG+osEX/ItL3FVj0=; b=o JWNf+AhsFrF9nOLxVDqOZ8FdvdbRzSTmII5OxhRB2KUgGxW/ATRV0GJIRWytXhNA Wq02XJq0SvBQkCteXGhXtMEIwuQV5sDpPce5i+w/J7u+sqnYBqiwcittV1Q54ebU 4ZdeE8dqtQ+kMX3q9vBIzJLdgCLy55AxvVk3aGDiM7l75MoUBcTDQ5CwFFYAxreI 6BiJj0rDfDqVwGTEfT3M68GCBeGOUSyFvqA+b2B+t2dSxb+HGztpU92HjrFAosDv Y0INryihyJC76KFK33AVqwJZJQZZl5dkiU4OlIRO9sM85BWlt47gFWM4pI0Uk7jD NEPTk2GHvwQvynhC6g86w== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeftddrudefgdehfecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtgfesthhqredtreerjeenucfhrhhomhepfdfnrghr rhihucfirghrfhhivghlugdfuceolhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtoh hmqeenucggtffrrghtthgvrhhnpeffffffjeffudfggeevvdeitdetvdfgjefffeffjeel feejteevheeghffhvdfgleenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmh grihhlfhhrohhmpehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomh X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 2F71D1700093; Mon, 1 Jul 2024 08:37:44 -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: <1b4acf29-968a-4731-9d64-a1945396df3c@app.fastmail.com> In-Reply-To: References: <4ECBB519-B129-426F-93AE-33738A1ABA06@miles.systems> <4996ae09-e5eb-4a8b-90e2-7461805c4cb7@app.fastmail.com> Date: Mon, 01 Jul 2024 12:37:14 +0000 To: "php internals" Subject: Re: [PHP-DEV] [Initial Feedback] Typed Arrays Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Mon, Jul 1, 2024, at 4:48 AM, Micha=C5=82 Marcin Brzuchalski wrote: > pon., 1 lip 2024 o 03:01 Larry Garfield napis= a=C5=82(a): >> Contextual point: Nearly every other major language at this point tha= t has a meaningful standard library has gone with a three-separate-objec= t approach (Seq, Set, Dict, called various things). At least Python, Ja= vascript, Rust, Kotlin, and Swift, in my research. (Go doesn't, but Go = avoids having features by design.) And AFAIK *every* language except PH= P and Lua separates sequences from dictionaries. Typed arrays will not = full resolve the seq vs dict problem, which is arguably PHP's original s= in. 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-b= est alternative to generics, essentially. It is less ergonomic, no ques= tion, but can also be implemented without generics, and so is about 5x e= asier to do. If we could get native generics, then I think everyone inv= olved agrees building collections off of that -- in essentially the same= way as every language I mentioned above --- would be preferable to a cu= stom one-off syntax. >>=20 >> --Larry Garfield > > Considering other languages it is worth mentioning that Java and C#=20 > have generics AND typed arrays that act as a typed list/seq so sure it=20 > doesn't solve all problems otherwise these languages wouldn't have bot= h=20 > of them. I believe in those languages Array came first, and then the collections = were added later when they determined that Array was insufficient and to= o low-level. (I'm not an expert on the history of either language, but = that's my understanding from reading their documentation.) Using the co= llections is the preferred approach now for most applications. > From my personal experience, a typed list/seq solves most cases where = I=20 > need the elements of an array to be strictly instances of a specific=20 > type. > What I see typed list/seq like `string[]` has more ergonomics, it can=20 > be used to interact between libraries and application code without=20 > creating intermediate objects, while collection proposal always=20 > requires declaring type - this simply multiplies the number of declare= d=20 > types and create more coupling where it is not needed! Also, most case= s=20 > I work with are just fine with using just foreach or array_ family=20 > functions. Yes, the need to create the monomorphized object yourself is a downside = of the dedicated collections syntax. No question. The trade-off is tha= t it's vastly easier to implement than either full generics or typed arr= ays. We haven't fully developed it yet as there's still experimentation= going on (by people with far more engine knowledge than me) to see if w= e can have our cake and eat it too. > This doesn't have to collide with generics in any way, as mentioned=20 > before in the thread these features may exist simultaneously, typed=20 > list/seq can translate in the future to a generic type. > I believe it'd make people's lives easier if we could have this in=20 > place soon. > Don't you agree? > > Cheers, > Micha=C5=82 Marcin Brzuchalski 1. I think you are vastly under-estimating the level of effort for makin= g typed arrays, and making them performant. Arnaud has been exploring t= hat, and it's far from trivial. "Have this in place soon" hand-waves ov= er an awful lot of complexity. 2. You're correct that typed arrays and generics could coexist in the la= nguage, if both could be implemented. But that is also a lot of work, w= ith overlapping problem spaces. 3. The core failing of typed arrays is that they still don't guarantee a= sequence; everything is still a string|int key dictionary with no suppo= rt for object keys, and PHP's screwy array-specific type casting. Frank= ly, people who don't see the challenges here have not tried to write arr= ay-handling libraries. :-) (Crell/fp taught me all kinds of things abou= t how broken arrays are, due to their fundamental unpredictability.) --Larry Garfield