0

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:

  1. Given an arbitrary node, I want to describe its first child, and then that node's first child, and so on recursively.

  2. 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?

closed as primarily opinion-based by user40980, Bart van Ingen Schenau, Ampt, jwenting, user22815 Nov 14 '14 at 18:11

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Given an arbitrary node, I want to describe its first child, and then that node's first child, and so on recursively. If it was a family tree, a node's first child is their "firstborn". If you are not working with family trees, it still might make enough sense. – FrustratedWithFormsDesigner Oct 31 '13 at 20:42
  • 3
    This question appears to be off-topic because it is a "name that thing" question. "Name that thing" are bad questions for the same reasons that "identify this obscure TV show, film or book by its characters or story" are bad questions: you can't Google them, they aren't practical in any way, they don't help anyone else, and allowing them opens the door for the asking of other types of marginal questions. See blog.stackoverflow.com/2012/02/lets-play-the-guessing-game – gnat Oct 31 '13 at 20:51
  • 4
    @gnat I disagree. Naming conventions are very relevant to programmers, and this question is specifically about terminology relating to tree relationships, a niche where others may have more expertise. If it were possible to Google and find an answer, I wouldn't have posted the question. – wst Oct 31 '13 at 21:07
  • 2
    I'm with @wst. Naming conventions are (or should be) just as on topic here as any other aspect of coding style or code organization. – Bobson Oct 31 '13 at 21:17
5

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.