Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109781 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 47646 invoked from network); 22 Apr 2020 18:56:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 22 Apr 2020 18:56:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A85C31804C2 for ; Wed, 22 Apr 2020 10:28:22 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 22 Apr 2020 10:28:21 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 70A375C0208 for ; Wed, 22 Apr 2020 13:28:21 -0400 (EDT) Received: from imap7 ([10.202.2.57]) by compute7.internal (MEProxy); Wed, 22 Apr 2020 13:28:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=/MeOHVsVeHgXSuhRuRqy6kEBnRrh6HYA1MxrA79Of PY=; b=tphriSiVp0ODSRDpgJTfDbmI99aM93ttLOvDuK7eddVQKf8g/FL8L0C0i OVQKL8yZNu5MOBjvzkalL06g4Wt3ltsKYyO1ucV6aLN3jaFf3Z9uv/W0Gn8fY+4C P4cEjo+jAo1CiDgMN50feXRsYm09msAMAb0IYa8XHfWmUe48X9uU/issrAwmPl7S 1LL1WHPPG0jStrNSrhhORcPkSxVqsp8uocD+d0OKWUUCdPae0j+HMvjiDEX3CqVy jECvbkvKX40Yi0uutMA8EJwD9BT1oze+g2aCZvR7YAxhtf2DGgI2l5eyUNkwZhdr MxalBv0kWmyynfD+mnx7mYHG3SzDA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrgeejgddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 1BD38180093; Wed, 22 Apr 2020 13:28:21 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.3.0-dev0-351-g9981f4f-fmstable-20200421v1 Mime-Version: 1.0 Message-ID: <4c1cd016-1e41-4ebc-afc4-d8d3cd1c319b@www.fastmail.com> In-Reply-To: References: Date: Wed, 22 Apr 2020 12:28:00 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Any interest in a list type? From: larry@garfieldtech.com ("Larry Garfield") On Tue, Apr 21, 2020, at 2:00 PM, Matthew Brown wrote: > Before I create an RFC or attempt a reference implementation, is there= any > interest in adding (and then obviously supporting in perpetuity) a lis= t > type? >=20 > The first line of PHP's documentation for "array" states: "An array in= PHP > is actually an ordered map". There are some optimisations that make ar= rays > with ordered integer keys faster, but I'd be interested in a separate = type > dedicated to *sequential* integer keys. Such a type would presumably > consume a little less memory. >=20 > Why "list" and not "vec" or similar? "list" is also a reserved word =E2= =80=93 I'm > imagining that you'd construct a list like >=20 > $l =3D list["a", "b", "c"]; >=20 > I imagine such a "list" type would be a subtype of "array" =E2=80=93 e= verywhere > that array was accepted, a list would be also, and it would have the s= ame > copy-on-write behaviour. >=20 > If people are interested in having that type, there's a question of wh= at to > do with >=20 > $some_list["a"] =3D 5; >=20 > Would you convert the $some_list to an array, or throw an exception? > Converting to an array would seem the more PHP-like thing to do. >=20 > Similarly, the behaviour of >=20 > $some_list[$key_out_of_current_range] =3D 5 >=20 > would be a matter of debate too =E2=80=93 would that turn $some_list i= nto an array, > or would it fill up any preceding entries in the array with null? >=20 > What other questions are there? Is a "list" type even a good fit for P= HP, > given most of its users seem pretty content with the current > swiss-army-knife array type? Most users don't realize that PHP's arrays-not-really-arrays have caused= millions of dollars in security breaches in the past. :-) They're dang= erous and to be avoided whenever possible. I'm very open to a list/sequence type, but as others have noted there's = a whole crapload of details to sort out to make it viable. In particula= r: * Is it an effective subclass of array? IMO, no. It should have absolu= tely no auto-conversion to/from an array whatsoever of any kind, period.= Keep them as separate as possible. * Should it even have random-access indexes? Honestly I'd say no; Just = support adding, removing, and iteration and generate the indexes on the = fly when iterating if necessary. * Should they pass like arrays or like objects? Many questions here. * Should they be mutable or immutable? I could argue for either one eff= ectively, I think, though I'd honestly favor immutable. * Are they iterable? Presumably, but does that have any weird implicati= ons for iterables that implicitly assume there are keys? How's that wor= k? * Does it make sense to add them without type enforcement via generics? = Lists + Generics would be lovely, but as we've seen Generics are Hard(t= m) and Not Imminent(tm). But would adding them now make a generic versi= on harder in the future? (I've no idea.) * Besides add/remove/iterate, what other baked-in functionality should t= hey have? Eg, can they be mapped/filtered/reduced? It would really suc= k to revisit lists and not fix that disconnect in the API. (Insert me t= alking about comprehensions and stuff here.) Ideally this would happen = as part of a larger review of how collections work at various levels, wh= ich are currently highly clunky. Those are all solvable problems (and I've likely forgotten several), but= they would have to be thought through extensively before an implementat= ion could be viable. --Larry Garfield