Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62363 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50343 invoked from network); 21 Aug 2012 21:29:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Aug 2012 21:29:33 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.133 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.133 oxmail.registrar-servers.com Received: from [64.22.89.133] ([64.22.89.133:56907] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 95/98-10139-CBDF3305 for ; Tue, 21 Aug 2012 17:29:32 -0400 Received: from [192.168.0.200] (5ad3285b.bb.sky.com [90.211.40.91]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 3F3AC7580A7; Tue, 21 Aug 2012 17:29:28 -0400 (EDT) Message-ID: <5033FD9C.6080106@ajf.me> Date: Tue, 21 Aug 2012 22:29:00 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Yasuo Ohgaki CC: Tjerk Anne Meesters , Rasmus Schultz , internals@lists.php.net References: <5033E0BC.8040507@ajf.me> <5033EAAB.6090502@ajf.me> <5033F1EA.4070701@ajf.me> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] re: removing an item from an array From: ajf@ajf.me (Andrew Faulds) On 21/08/12 22:18, Yasuo Ohgaki wrote: > 2012/8/22 Andrew Faulds : >> Er, so you're advocating adding another method to do the same thing? Why? > Because novices don't know about array_walk(). > I think I've written this over and over in this thread. So publicise array_walk() then. Don't add a new function. >> The whole point of this was to allow people to use arrays like sets, or >> easily remove list items. Not encourage people to use functional >> programming. >> >> Sure, people should use array_walk, but you've got to be kidding me if I you >> think I would honestly accept using this to remove array items by value: >> >> array_delete($array, function ($value) { return ($value == "that value"); >> }); >> >> I might as well use array_walk if we're going down this route. You seem to >> want to subvert the usefulness of this function and just provide an >> array_walk shorthand with less functionality. >> >> What I want is this: >> >> array_delete($array, "that value"); > I do not want this ;) > What's wrong with extensible way? It's for PHP 5.5, not PHP 4. But we have array_walk(). > array_delete($array, function ($v) { return ($v == "that value"); }); > > We can use ==, ===, <, >, <=, =>, <==, ==>, !=, !==, and so on. > We may pass them as parameter, > > array_delete($array, "that value", "!=="); > > but it does not look a modern way to do and it is not extensible > like with callable. No, it is a modern way. Modern and functional are not one and the same. > > Besides, how often we would like to delete elements based on > element's value? I guess it's not so often for most people. Uh, I thought that was the whole point of this suggestion. You seem to want to subvert the original intentions (making it easier to remove list items and treat arrays as sets), to providing a new functional mechanism for removing lots of array items satisfying a criteria. >> Much more readable, does what you expect, and provides a significant, >> noticeable value over array_walk here. > array_walk() is easy to use, IMHO. > People just don't know array_walk() can be used to delete > elements because of it's name. But adding a new function is NOT the solution. That is the job of documentation. That's like saying "people have no idea what strstr is, so let's make a new function with less functionality called string_position!". > > As I wrote in sample code, new array_delete is an intuitive > name and convenient than array_walk. They are like > array_pop/array_push and array_slice/array_splice to me. It's nothing like those. array_pop() and array_push() are simple, they take an array and an item to add. What's so terrible and evil and complex about making array_delete() remove an item? Why does it have to be functional and overcomplicated to do something we can already do, instead of providing a simple and convenient mechanism to remove an item by value? I do not understand this. Especially since, by your method, you should also provide a key since it provides no method to check item's key. Sorry, I just do not understand how your suggestion is useful. > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > >>> Regards, >>> >>> -- >>> Yasuo Ohgaki >>> yohgaki@ohgaki.net >>> >>> >>>>> As I mentioned earlier, array_walk() is the best way to delete elements >>>>> with PHP >>>>> more than a decade. It should be mentioned the Stack Overflow page, >>>>> but it's not. >>>>> >>>>> It's just like adding >>>>> array_pop()/array_push()/array_shift()/array_unshift() while >>>>> we have array_slice()/array_splice(). >>>>> >>>>> Regards, >>>>> >>>>> -- >>>>> Yasuo Ohgaki >>>>> yohgaki@ohgaki.net >>>> >>>> >>>> -- >>>> Andrew Faulds >>>> http://ajf.me/ >>>> >> >> -- >> Andrew Faulds >> http://ajf.me/ >> -- Andrew Faulds http://ajf.me/