i came across circumstances in the API design that have a flair of inconsistency:
- there's the
NodeBase.ancestors
method and its complementary way to traverse a tree is NodeBase.child_nodes
with the recurse
argument set to True
. this argument is unique among the methods to navigate from a node, all other only take filters as arguments.
- the XPath axes implementations directly use a set of concordant navigational methods that often have descriptive names made of a verb, an adjective and a mathematical term (e.g.
NodeBase.iterate_next_nodes
), while the axes names all refer to the metaphor of kinship in Homo sapiens cultures (e.g. following-siblings
).
- the names of
NodeBase
's methods that refer to other nodes use either descriptions (e.g. next_node
) or use the kinship metaphor (e.g. parent
).
- looking closer at it (see below), the names' structures are quiet diverse.
i'm certain i'd like to deprecate the NodeBase.child_nodes
' recurse
argument in favor for a NodeBase.descendants
iterator.
the current names can be described like this:
name |
structure* |
parent & unfiltered shortcuts |
|
first_child |
rk |
last_child |
rk |
last_descendant |
rk |
parent |
k |
fetching a single relative |
|
next_node |
rm |
next_node_in_stream |
rmc |
previous_node |
rm |
previous_node_in_stream |
rmc |
iterating |
|
ancestors |
K |
child_nodes |
kM |
iterate_next_nodes |
vrM |
iterate_next_nodes_in_stream |
vrMc |
iterate_previous_nodes |
vrM |
iterate_previous_nodes_in_stream |
vrMc |
adding nodes |
|
add_next |
vr |
add_previous |
vr |
insert_child |
vk |
prepend_child |
vk |
* legend: r
- relational adjective, k
/K
- kinship substantive (s./pl.), m
/M
- mathematical term (s./pl.), c
- contextual aspect, v
- verb
this is the distribution of composed structures, that's ten forms made of five types:
k .
K .
kM .
rk ...
rm ..
rmc ..
vk ..
vr ..
vrM ..
vrMc ..
with naming principles in general, it's a matter of gusto. personally i find the descriptive ones clearer and the kinship metaphor both inane and miserable. certainly many will find these customary. and an obvious problem is that i hadn't come up with something descriptive for ancestors
, child_nodes
and parent
.
a point in favor for the XPath concept beside consistency imo is that it defines forward and reverse axes as behaviour. that would set a frame to clearly answer the question raised in #30, so that a given input sequence is inserted in axis direction.
in order to not lead users to the temptation to guess, an obvious way to do it can be be provided by methods names that follow a stringent structure.
a first step to streamlining can be to omit the node
term for objects where it can be replaced by or reduced to kinshiply terms. also, methods that can take multiple nodes as input should use a pluralized form. but afaik there's no plural of following in poor english:
old name |
structure |
old or new name |
parent & unfiltered shortcuts |
|
|
first_child |
rk |
first_child |
last_child |
rk |
last_child |
last_descendant |
rk |
last_descendant |
parent |
k |
parent |
fetching a single relative |
|
|
next_node |
rm ⇘ rk |
following_sibling |
next_node_in_stream |
rmc ⇘ r |
following |
previous_node |
rm ⇘ rk |
preceding_sibling |
previous_node_in_stream |
rmc ⇘ r |
preceding |
iterating |
|
|
ancestors |
K |
ancestors |
child_nodes |
kM ⇘ K |
children |
|
⇘ K |
descendants |
iterate_next_nodes |
vrM ⇘ vrK |
iterate_following_siblings |
iterate_next_nodes_in_stream |
vrMc ⇘ vr |
iterate_following |
iterate_previous_nodes |
vrM ⇘ vrK |
iterate_preceding_siblings |
iterate_previous_nodes_in_stream |
vrMc ⇘ vr |
iterate_preceding |
adding nodes |
|
|
add_next |
vr ⇘ vrK |
add_following_siblings |
add_previous |
vr ⇘ vrK |
add_preceding_siblings |
insert_child |
vk ⇘ vK |
insert_children |
prepend_child |
vk ⇘ vK |
prepend_children |
this is the distribution of seven forms made of three word types:
k .
K ...
rk .....
r ..
vK ..
vr ..
vrK ....
given said lack of the nouns followings (in case of the intended meaning) and precedings, the verb iterate is necessary, and hence consistency in this corner is achieved by adding it where it's missing:
old name |
structure |
old or new name |
parent & unfiltered shortcuts |
|
|
first_child |
rk |
first_child |
last_child |
rk |
last_child |
last_descendant |
rk |
last_descendant |
parent |
k |
parent |
fetching a single relative |
|
|
next_node |
rm ⇘ rk |
following_sibling |
next_node_in_stream |
rmc ⇘ r |
following |
previous_node |
rm ⇘ rk |
preceding_sibling |
previous_node_in_stream |
rmc ⇘ r |
preceding |
iterating |
|
|
ancestors |
K ⇘ vK |
iterate_ancestors |
child_nodes |
kM ⇘ vK |
iterate_children |
|
⇘ vK |
iterate_descendants |
iterate_next_nodes |
vrM ⇘ vrK |
iterate_following_siblings |
iterate_next_nodes_in_stream |
vrMc ⇘ vr |
iterate_following |
iterate_previous_nodes |
vrM ⇘ vrK |
iterate_preceding_siblings |
iterate_previous_nodes_in_stream |
vrMc ⇘ vr |
iterate_preceding |
adding nodes |
|
|
add_next |
vr ⇘ vrK |
add_following_siblings |
add_previous |
vr ⇘ vrK |
add_preceding_siblings |
insert_child |
vk ⇘ vK |
insert_children |
prepend_child |
vk ⇘ vK |
prepend_children |
resulting in this distribution of six forms:
k .
rk .....
r ..
vK .....
vr ..
vrK ....
one last measurement for streamlining could be to prefix methods to get a single node with the verb fetch
(e.g. fetch_following_sibling
) leading to a distribution with also six forms like so:
k .
rk ...
vK .....
vr ....
vrk ..
vrK ....
a further question could be whether also the self-or-*
axes from XPath should be adapted as iterator methods on NodeBase
. i'm quiet sure that i already had situations where i could have used it, but it's also simple to work around it. though implementation and maintenance would be almost no-cost.
the risk to introduce new bugs with the possible changes is very low, so it'd be okay to include it in the 0.4 release imo. but the triviality of the issue also doesn't make it urgent to decide on.