This is a naming things question. I am processing trees (XML documents), and there are often special rules applied to nodes based on structure. It’s been very difficult coming up with concise naming conventions for some cases, namely for nodes in the first position among their siblings, along with some recursive relationship:
-
Given an arbitrary node, I want to describe its first child, and then that node’s first child, and so on recursively.
-
Given another arbitrary node, I want to describe its parent if the parent is first among its siblings, and that parent’s parent if it’s first, and so on recursively.
Is there existing terminology to describe these tree positions? How would you name a variable or function that captures one of these cases so that it’s intuitive to an unfamiliar developer trying to understand an algorithm?
4
I like to use the word Primary
in situations where the word First
isn’t quite right, but is close. It indicates that it’s special in some way, without actually depending on an ordered enumeration. First
implies a Second
, Third
and so on, but Primary
could be paired with everything else
or Secondary
, Tertiary
, and only then everything else
.
Given an arbitrary node, I want to describe its first child, and then that node’s first child, and so on recursively.
I’d call this one PrimaryDescendant
. After all, if you enumerate every final descendant of a given node, in order, it’s the one that will be first. If you’re referring to the “first child” status by itself, that’d just be FirstChild
.
Given another arbitrary node, I want to describe its parent if the parent is first among its siblings, and that parent’s parent if it’s first, and so on recursively.
This one is harder, but I’d probably try to be consistent and call it PrimaryAncestor
.