Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:116070 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98483 invoked from network); 17 Sep 2021 12:35:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 17 Sep 2021 12:35:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8166D1804E3 for ; Fri, 17 Sep 2021 06:15:19 -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=-1.5 required=5.0 tests=BAYES_00,KHOP_HELO_FCRDNS, SPF_HELO_NONE,SPF_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS16276 94.23.0.0/16 X-Spam-Virus: No X-Envelope-From: Received: from processus.org (ns366368.ip-94-23-14.eu [94.23.14.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 17 Sep 2021 06:15:18 -0700 (PDT) Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by processus.org (Postfix) with ESMTPA id B74F15101324; Fri, 17 Sep 2021 13:15:12 +0000 (UTC) Message-ID: Date: Fri, 17 Sep 2021 15:15:11 +0200 MIME-Version: 1.0 Content-Language: en-US To: tyson andre , "internals@lists.php.net" References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Authentication-Results: processus.org; auth=pass smtp.auth=pierre-php@processus.org smtp.mailfrom=pierre-php@processus.org X-Spamd-Bar: / Subject: Re: [PHP-DEV] RFC: Add `final class Vector` to PHP From: pierre-php@processus.org (Pierre) Le 17/09/2021 à 14:54, tyson andre a écrit : > Aside: https://github.com/TysonAndre/pecl-teds#iterable-functions > starts doing that, but evaluating eagerly instead of using generators. > I still don't think there's enough functionality yet to re-propose that. Nice to know this, I wasn't aware it even existed, I'll have a look. >> I know this vector proposal is not about that, but nevertheless, in my >> opinion, it must start preparing the terrain for this, or all other RFC >> in the future will only create new isolated data structures and make the >> SPL even more inconsistent. > It's possible, but I don't know what others think. > > 1. https://www.php.net/manual/en/class.ds-collection.php actually seems fairly universal, but out of scope, and I don't know if people would json encode a SplMaxHeap. Right now that isn't implemented and the value is always `{}` > 2. `add($value)/remove($value)/contains[Value]($value)` is limited to some structures - Only containsValue() would apply to ArrayObject/SplObjectStorage. The others wouldn't work since you'd need to know the keys as well. That's true, vector is a bit aside of what we'd expect from a full blown collection API, it's a very basic structure in the end so it can probably live on its own. > Also, > > - Union type/intersection type support exists, so allowing any generic collection interface is less urgent. That's right, but I don't think that union/intersection types solve the generic collection problem, you'd still have to match for specific class names or interfaces if methods are not rationalised in a single API. > - equals() may work, though infinite recursion (or the way it is or isn't detected) in circular data structures is a potential objection, especially with lack of stack overflow detection - php just crashes/segfaults without a useful method when it runs out of stack space. > > For the ones that are universal, Countable/ArrayAccess/IteratorAggregate/Traversable already exist. Yes, they exist, but I wouldn't place IteratorAggregate as being part of the interface, it's about implementation, but right. Anyway altogether they form a very poor API covering a very small surface and I'd imagine those becoming a legacy thing if a new API was introduced. > Also, as you said, this RFC is not about that. > Requiring that anyone systematically overhaul existing data structures before adding any new data structures > seems like it would significantly delay or discourage any future additions of data structures. > > In the immediate future, an RFC only doing that would not have much short-term benefit to users - it would also have short-term drawbacks for what I consider not enough benefit, > if adopting that interface made libraries drop support for older php versions. I think your point is legit, and a part of me agrees with you, probably having some data structure before thinking about rationalisation is something that would make people move forward. Nevertheless it's always very difficult to change things once they're here, and the whole problem. I crave so deeply for a complete, easy to use, well documented and standard collection API that I always jump on such RFC's to tell people "stop using DS, stop using Doctrine Collections, stop using "[name it here] collection", please everyone, let's design, implement and use the single and same one, so that we will never have to support them all (them being the 1,000 existing duplicated library in userland) in our framework or business code. Thanks a lot for your answer and you time, despite the fact I still think that designing a collection first can still be done, having the vector type/class in core is a great idea. Regards, -- Pierre