cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Menard <nirvd...@gmail.com>
Subject Re: [suggestion] unmodifiable toMany lists
Date Wed, 11 Nov 2009 15:44:59 GMT
On Wed, Nov 11, 2009 at 1:13 AM, Dirk Olmes <dirk@xanthippe.ping.de> wrote:

>> Right. They are...but this (I believe) is too easily exposed to user
>> code.  e.g.,
>> for (Bar relation : foo.allBars()) {
>>     if (some condition) {
>>         foo.removeFromAllBars(relation); // will throw exception
>>     }
>> }
>
> Err, why is this? Because you're modifying the collection you're
> iterating over? I'd rather fix the iterator then.

The "problem" exists outside the context of an iterator, too.  What
would you expect the semantics to be of the following?

foo.allBars.remove(for.allBars.get(0));

Should it just modify the in-memory list or should it represent the
backing DB and represent a DELETE operation?

It gets a little worse when you add your own custom collection methods
(i.e., not DB backed) and it's not clear what type you're working
with.

Don't get me wrong, it's wholly a human problem.  But, false
expectations can lead to tedious debugging sessions and adoptions of
seemingly tenuous programming habits.

-- 
Kevin

Mime
View raw message