Are implementations expected to preserve the order of nodes in the document root? #154
-
"Children should be used if an order-sensitive key/value data structure must be represented in KDL," doesn't necessarily mean that nodes are order sensitive in the document root, so... /- "Explicitly Unordered" - answer=42 \ author="Douglas Adams" \ work="The Hitchhiker's Guide to the Galaxy" /- "Explicitly Ordered" - { answer 42 author "Douglas Adams" work "The Hitchhiker's Guide to the Galaxy" } /- "Explicitly a Different Order" - { author "Douglas Adams" work "The Hitchhiker's Guide to the Galaxy" answer 42 } /- "What about this..." answer 42 author "Douglas Adams" work "The Hitchhiker's Guide to the Galaxy" /- "And this..." author "Douglas Adams" work "The Hitchhiker's Guide to the Galaxy" answer 42 Are the last two equivalent? If the node order in the document root isn't relevant, that allows implementations to naively rely on the object and table handling native to their programming environment even when these don't guarantee that the node order will be preserved, e.g. in Lua, the order of keys in tables will generally be preserved, but it isn't guaranteed when there are deletions and insertions. If node order in the root is not preserved, that has implications when designing parsers that don't consume the entire document before they begin producing results The documented behavior of Lua means that my implementation should preserve node order in both root and children when a KDL document is round tripped, assuming that there are either no deletions (insertions will be made at the end of the document) or that there are no insertions after a deletion occurs (deletion will not change the order of remaining nodes, but subsequent insertions are made to the first available position). I'll obviously need to repack children on occasion, but it would be nice to avoid repacking the document root Also, this question would likely be answered by a test suit. I don't remember seeing one, but that doesn't mean it doesn't exist... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It depends on your use case, honestly. At the KDL level itself, those last two are two completely different documents, because child nodes are ordered. But it your parser is putting things into a hash table in a use case where users don't actually care about order, that's actually fine? So I guess the answer is "it depends on the use case" |
Beta Was this translation helpful? Give feedback.
It depends on your use case, honestly.
At the KDL level itself, those last two are two completely different documents, because child nodes are ordered.
But it your parser is putting things into a hash table in a use case where users don't actually care about order, that's actually fine?
So I guess the answer is "it depends on the use case"