In the previous entry I discussed changes to Amara's mutation API. In the original discussion one of the things that came up was the old element/attribute conundrum. Take the following document:
Users like to be able to access both elements and attributes using friendly Python idiom, but here we have a name clash on the resulting a
object.Right now Amara exposes the attribute as a.b
and the element as a.b_
, using name mangling to disambiguate.
The important thing to remember, however, is that such clashes are quite rare in practice, even when you throw in namespaces, so such mangling is rarely necessary, and I personally think Amara's current behavior makes sense. But I may just have a blind spot, so I've been paying attention to suggestions from others.
Jeremy Kloth suggested just always using different idioms. a.[u"b"]
for the attribute and a.b
for the element. This is not a bad idea, but I feel that given that clashes are rare, that it complicates the common case just to aid the rare case.
Luis Miguel Morillas had an idea I consider almost the opposite. Rather than completely separate element/attribute idioms, Luis suggests embracing how Amara has unified them. Right now Amara rolls up multiple elements of the same name in a convenient way:
Works such that a.b
or a.b[0]
yields the element with y
and a.b[1]
yields the element with z
. Luis thinks that the following case should just be an extension of this:
And then a.b
or a.b[0]
would yields the attribute value (u"x"
), a.b[1]
would yield the element with y
, and a.b[2]
would yield the element with z
. I kinda think of this idea as "so crazy it almost makes perfect sense", but it's way too big a change to introduce before Amara 1.0. I'd be curious to hear what others think of it. Luis actually brings it up in the context of mutation--see his original post (scroll to the bottom)--but I figure that the mutation API will follow naturally from the access API, so I'm focusing my thoughts a bit.