Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Automatic detach

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Laurent Bihanic <laurent.bihanic AT atosorigin.com>, XOM-interest <XOM-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] Automatic detach
  • Date: Thu, 19 Sep 2002 10:33:03 -0400

At 10:33 AM +0200 9/19/02, Laurent Bihanic wrote:


- Automatic detach: Having to call detach when moving nodes from one place to another is realy cumbersome. A typical example is sorting a list of children. Why not support an automatic-detach mode so that programmer can move nodes freely?


It doesn't strike me as a huge burden on the programmer to have to detach a node first. I think two XOM principles are at issue here:

1. There's exactly one way to do it: since we need a detach method for non-moves, we should not duplicate it as part of insert.

2. Least surprise: would a developer be more surprised to find out that a node had been automatically detached when they forgot it had a parent and got the exception? Or would it be more surprising to later discover that a node had been detached? I'm not sure.

My thinking is that moves from one part of the tree to another are a relatively rare operation, so I'm not too concerned with optimizing them for the client. Calling detach() and then inserting is not that much harder than just inserting. I am worried about someone accidentally inserting something they didn't mean to detach. I've made this mistake myself more than once, and personally I prefer to get the exception so I see my error up front.
--

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo AT metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
| XML in a Nutshell, 2nd Edition (O'Reilly, 2002) |
| http://www.cafeconleche.org/books/xian2/ |
| http://www.amazon.com/exec/obidos/ISBN%3D0596002920/cafeaulaitA/ |
+----------------------------------+---------------------------------+
| Read Cafe au Lait for Java News: http://www.cafeaulait.org/ |
| Read Cafe con Leche for XML News: http://www.cafeconleche.org/ |
+----------------------------------+---------------------------------+




Archive powered by MHonArc 2.6.24.

Top of Page