Fix problematic default value for BObjectList::RemoveItem() deleteIfOwning parameter
|Reported by:||bonefish||Owned by:||nobody|
|Has a Patch:||no||Platform:||All|
This has bitten me more than once already: When a
BObjectList is owning its elements the call
RemoveItem(myObject) deletes the supplied object. This is problematic for the following reasons:
- The method is called
*Remove*Item()which does not imply that the item is deleted.
- The behavior differs from
RemoveItemAt()which never deletes the object.
The change causing the least work would be to just remove the default value for the
deleteIfOwning parameter. Then the API user does have to explicitly decide whether the deletion is desired or not and it is far less likely that it happens accidentally. This solution is not so great for the not-owning case, though.
A cleaner solution (though possible troublesome for third-party developers) would be to remove the parameter altogether, change the method not to delete the object, and introduce a
EraseItem() method. Besides making it even less likely to accidentally delete the object (it's way more obvious than a
false argument) such a method would also make sense for lists that aren't owning the items.