[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Dropping objects via List
From: |
Sven N. Thommesen |
Subject: |
Re: Dropping objects via List |
Date: |
Fri, 11 Jul 1997 09:38:54 -0500 |
At 10:40 PM 7/10/97 -0500, you wrote:
>Sven Thommesen writes:
>
>> The documentation for List and Collection states that the message
>>
>> [ myList removeAll ]
>>
>> will empty a list, but if you want to actually delete the objects being
>> pointed to by the list, you have to cycle through them and drop them
>> individually first.
>>
>> Looking at the code, I found that there is an [undocumented ???] method
>>
>> [ myList deleteAll ]
>>
>> which will not only empty the list of pointers but also drop (remove from
>> memory) all objects pointed to by the list.
>>
>> Came in really handy in my case!
>
>The trouble is, it doesn't generalize, and so even though there's an old
>version of the method that hasn't yet been cleaned out of the code, it's
>not documented, not supported, and will be removed from a future version.
>
>A list can reference the same member multiple times, and the drop will
>
>behave very rudely if it tries to drop a member a second time that has
>already been dropped. The method is also redundant with the forEach:
>method, which should provide sufficient convenience if you know that you
>can get away with dropping members that don't occur multiple times. The
>following code does the same that deleteAll would do:
>
> [aList forEach: M(drop)];
> [aList removeAll];
>
>It's a relatively fine call, but generally speaking the libraries don't
>provide methods that just combine the effect of a small number of other
>methods; such methods add a lot of clutter to the interface and can become
>more complicated to document than the occasional coding convenience they
>provide. It is important to document the standard, convenient idioms that
>accomplish the same things, however; that needs to be part of the usage
>guides/tutorials for each library that nobody's written yet. It is, of
>course, very important that you drop objects referenced by a collection
>separate from the collection itself, but dropping them separately is also
>needed since the same objects could also be referenced by multiple
>collections.
>
>Roger Burkhart
>
Roger, I really didn't intend for this to become a philosophical
discussion, but since you promise to remove the method I just proudly
announced I had found, I can't resist an argument!
While I understand your concern about 'clutter' in the interface (we've
been over this before, over the random library), I *do* believe a case can
be made for providing combination methods for the sake of convenience --
especially when the combination performs an action that is a (how to put
it) natural mental unit.
Think of it this way -- if you want an employee to clean the office, you
*could* give him/her detailed, step-by-step instructions -- but why waste
the energy, if he/she knows how, so that all you have to do is say 'clean
the office' ? [Putting on my economist's hat for a moment, this is one of
the differences between having employees and subcontracting: generally,
with subcontractors, you specify the what, but not the detailed how ...]
As for the specific method(s) we're discussing, attempting to drop an
object for the second time will cause a core dump whether you do
[ myList deleteAll ];
or
[ myList forEach: M(drop) ];
[ myList removeAll ];
If a user has a list that *does* contain duplicates, they should not be
using that list to drop objects. If they have a list that *may* contain
duplicates, life gets complicated ...
So, a suggestion: if you don't want to provide a 'redundant' deleteAll
method, how about a -deleteAll method that first removes any duplicates
from the list, thus saving the user from possible core dumps? That's a
functionality better provided once by a wizard than attempted many times by
newbies ...
--Sven
==================================
Swarm-Support is for discussion of the technical details of the day
to day usage of Swarm. For list administration needs (esp.
[un]subscribing), please send a message to <address@hidden>
with "help" in the body of the message.
==================================