Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » [PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon [RSS Feed]

#1 Dec. 19, 2010 14:50:50

Gustavo L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon


On Sun, 19 Dec 2010 05:33:56 -0000, Matthew Turland <tobias***@*mail.com>
wrote:Attached are source/test and manual patches for the addition of two
methods to the SplObjectStorage class. These methods, removeCommon and
removeUncommon, add support for the difference and intersection set
operations, respectively.I'm sorry, I must be missing something because what exactly is the
difference between removeCommon and removeAll?

I think it's unfortunate that SplObjectStorage chose the Java naming of
the set operation methods instead of following PHP's choice for arrays:

* "diff" for the complement
* "intersect" for the intersection
* "merge" for the union

(You could argue that Java's naming is more appropriate because, contrary
to the array functions, the methods have collateral affects that are
better expressed with "remove" and "add".)

In any case, consistency would dictate the difference should be called
"removeAll", intersection should be called "retainAll" and the union
should be called "addAll".

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#2 Dec. 19, 2010 15:04:07

Hannes M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon


On Sun, Dec 19, 2010 at 15:49, Gustavo Lopes <glo***@*ebm.ist.utl.pt> wrote:
> On Sun, 19 Dec 2010 05:33:56 -0000, Matthew Turland <tobias***@*mail.com>
> wrote:
>
>> Attached are source/test and manual patches for the addition of two
>> methods to the SplObjectStorage class. These methods, removeCommon and
>> removeUncommon, add support for the difference and intersection set
>> operations, respectively.
>
> I'm sorry, I must be missing something because what exactly is the
> difference between removeCommon and removeAll?

Is this just bikeshedding over the method names, or did you not bother
reading the patches? (the doc patch even includes examples).

-Hannes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#3 Dec. 19, 2010 15:17:20

Gustavo L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon


On Sun, 19 Dec 2010 15:12:17 -0000, Hannes Magnússon<hannes.magnus***@*mail.com> wrote:On Sun, Dec 19, 2010 at 16:05, Gustavo Lopes <glo***@*ebm.ist.utl.pt>wrote:On Sun, 19 Dec 2010 15:03:22 -0000, Hannes Magnússon
<hannes.magnus***@*mail.com> wrote:On Sun, Dec 19, 2010 at 15:49, Gustavo Lopes <glo***@*ebm.ist.utl.pt>wrote:On Sun, 19 Dec 2010 05:33:56 -0000, Matthew Turland<tobias***@*mail.com> wrote:Attached are source/test and manual patches for the addition of twomethods to the SplObjectStorage class. These methods, removeCommonand removeUncommon, add support for the difference and intersectionsetoperations, respectively.I'm sorry, I must be missing something because what exactly is the
difference between removeCommon and removeAll?Is this just bikeshedding over the method names, or did you not bother
reading the patches? (the doc patch even includes examples).I did, and near the end it has:

SPL_ME(SplObjectStorage, removeAll, arginfo_Object, 0)
+ SPL_ME(SplObjectStorage, removeCommon, arginfo_Object, 0)

So there's already a removeAll.Read the doc patch. The description says it all, but if you still
wonder then look at the example.In the example, substituting removeCommon by removeAll has exactly thesame result:<?php
$a = (object) 'a';
$b = (object) 'b';
$c = (object) 'c';

$foo = new SplObjectStorage;
$foo->attach($a);
$foo->attach($b);

$bar = new SplObjectStorage;
$bar->attach($b);
$bar->attach($c);

$foo->removeAll($bar);
var_dump($foo->contains($a));
var_dump($foo->contains($b));

gives

bool(true)
bool(false)


Could you please explain the difference instead of telling me to RTFP?

--
Gustavo Lopes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

#4 Dec. 19, 2010 15:24:52

Hannes M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

[PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon


On Sun, Dec 19, 2010 at 16:16, Gustavo Lopes <glo***@*ebm.ist.utl.pt> wrote:
> On Sun, 19 Dec 2010 15:12:17 -0000, Hannes Magnússon
> <hannes.magnus***@*mail.com> wrote:
>
>> On Sun, Dec 19, 2010 at 16:05, Gustavo Lopes <glo***@*ebm.ist.utl.pt>
>> wrote:
>>>
>>> On Sun, 19 Dec 2010 15:03:22 -0000, Hannes Magnússon
>>> <hannes.magnus***@*mail.com> wrote:
>>>
>>>> On Sun, Dec 19, 2010 at 15:49, Gustavo Lopes <glo***@*ebm.ist.utl.pt>
>>>> wrote:
>>>>>
>>>>> On Sun, 19 Dec 2010 05:33:56 -0000, Matthew Turland
>>>>> <tobias***@*mail.com> wrote:
>>>>>
>>>>>> Attached are source/test and manual patches for the addition of two
>>>>>> methods to the SplObjectStorage class. These methods, removeCommon and
>>>>>> removeUncommon, add support for the difference and intersection set
>>>>>> operations, respectively.
>>>>>
>>>>> I'm sorry, I must be missing something because what exactly is the
>>>>> difference between removeCommon and removeAll?
>>>>
>>>> Is this just bikeshedding over the method names, or did you not bother
>>>> reading the patches? (the doc patch even includes examples).
>>>>
>>>
>>> I did, and near the end it has:
>>>
>>>       SPL_ME(SplObjectStorage,  removeAll,   arginfo_Object,        0)
>>> +       SPL_ME(SplObjectStorage,  removeCommon,   arginfo_Object,     0)
>>>
>>> So there's already a removeAll.
>>>
>>
>> Read the doc patch. The description says it all, but if you still
>> wonder then look at the example.
>>
>
> In the example, substituting removeCommon by removeAll has exactly the same
> result:

Haha. I was under the impression removeAll().. did what the method
name says, sorry :P

-Hannes

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » [PHP-DEV] [PATCH] SplObjectStorage::removeCommon and removeUncommon [RSS Feed]

Board footer

Moderator control

Enjoy the 17th of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support