Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84431 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89118 invoked from network); 8 Mar 2015 10:51:40 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Mar 2015 10:51:40 -0000 Authentication-Results: pb1.pair.com header.from=gregory@luni.fr; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=gregory@luni.fr; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain luni.fr designates 188.165.39.161 as permitted sender) X-PHP-List-Original-Sender: gregory@luni.fr X-Host-Fingerprint: 188.165.39.161 15.mo6.mail-out.ovh.net Received: from [188.165.39.161] ([188.165.39.161:48925] helo=15.mo6.mail-out.ovh.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 38/11-17427-AB92CF45 for ; Sun, 08 Mar 2015 05:51:39 -0500 Received: from mail625.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo6.mail-out.ovh.net (Postfix) with SMTP id 1EAB8FF970E for ; Sun, 8 Mar 2015 11:51:35 +0100 (CET) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 8 Mar 2015 12:51:35 +0200 Received: from gaz43-2-78-217-8-218.fbx.proxad.net (HELO MacBook-Pro-de-Gregory.local) (gregory@luni.fr@78.217.8.218) by ns0.ovh.net with SMTP; 8 Mar 2015 12:51:33 +0200 Message-ID: <54FC29B4.4000105@luni.fr> Date: Sun, 08 Mar 2015 11:51:32 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: Thomas Gielfeldt , Benjamin Eberlei CC: PHP Internals References: In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 3005308327028284875 X-Ovh-Remote: 78.217.8.218 (gaz43-2-78-217-8-218.fbx.proxad.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: -100 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejledrheehucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeejledrheehucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd Subject: Re: [PHP-DEV] Feature request and RFC From: gregory@luni.fr (=?UTF-8?B?R3LDqWdvcnkgUGxhbmNoYXQ=?=) Le 24/02/2015 20:20, Thomas Gielfeldt a écrit : > 2015-02-24 17:36 GMT+01:00 Benjamin Eberlei : > >> Hi, >> >> On Tue, Feb 24, 2015 at 5:17 PM, Thomas Gielfeldt >> wrote: >> >>> Hi internals. >>> >>> I've made PR proposing a feature request: A new interface Sortable. >>> >>> https://github.com/php/php-src/pull/1116 >>> >>> If possible, I would like to create and RFC describing this in more >>> detail, >>> and perhaps get a voting on. >>> >> >> so you need to implement all methods? This can probably be considered a >> violation of the Interface Segregation Principle. But adding an interface >> for each method seems a bit much as well. >> > > Yeah, I've thought of this as well. PHP has got a load of sort functions. > I've also considered other options: > > 1.) 5 interfaces for, respectively, (r)sort, a(r)sort, k(r)sort, u(a|k)sort > and nat(case)sort, with 2-3 methods per interface. > 2.) Same as above, but with a flag for reverse instead of a dedicated > function resulting in 5 interfaces with 1-3 methods each. > 3.) 1 interface with 2 methods, sort() and usort(), and flags for reverse, > key and maintaining index. > > I did consider the latter much, but wasn't sure if the methods would get > too monolithic. > > I also did consider an interface per method. Briefly. :-) > > > >> >>> Thanks >>> >>> Br, >>> >>> Thomas Gielfeldt >>> >> >> > Hi, I posted a message in the discussion about function names consistency which is, in part, related to this thread. The main subject may be defining a consistent API, but one part is about ordering native arrays. http://news.php.net/php.internals/84429 I started to write some documentation for an OO API dedicated to arrays - and hence sorting arrays. https://github.com/gplanchat/php-oop-api/blob/master/doc/array-sorter.md I wrote in this document an abstract method, named SplArraySorter, which only has an abstract sort() method. Every variant implements the functionalities of one or multiple array sorting native functions. The point I want to come after is that the collection should not be aware of how we would want to sort it, but let this control to a external object. Therefore, the way collections may be actually sorted would become dependent on an external object and be changed on the fly by the program itself, without having to rewrite any line of code. This has the avantage of letting you have the control over any source code, whether you are the author (or able to change it) or if this code comes from a dependency (PEAR, Composer, ect...). So, to make it more visual, I would suggest intead to create the 2 interfaces Sorter and Sortable, which could be vritten as :