[haiku-bugs] [Haiku] #9627: Fix problematic default value for BObjectList::RemoveItem() deleteIfOwning parameter

  • From: "bonefish" <trac@xxxxxxxxxxxx>
  • Date: Sat, 06 Apr 2013 13:10:21 -0000

#9627: Fix problematic default value for BObjectList::RemoveItem() 
deleteIfOwning
parameter
------------------------------+------------------------------
 Reporter:  bonefish          |        Owner:  axeld
     Type:  enhancement       |       Status:  new
 Priority:  normal            |    Milestone:  R1
Component:  Kits/Support Kit  |      Version:  R1/Development
 Keywords:                    |   Blocked By:
 Blocking:                    |  Has a Patch:  0
 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 `DeleteItem()` or `EraseItem()`
 method. Besides making it even less likely to accidentally delete the
 object (it's way more obvious than a `true`/`false` argument) such a
 method would also make sense for lists that aren't owning the items.

--
Ticket URL: <http://dev.haiku-os.org/ticket/9627>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: