4 ms·
> Agreed, infinite loops are a little hard to protect using asserts. assert(is_tree(comment_graph)) Typically, a composite entity (like an "item" on HN wh
by badgar 14y ago
> Agreed, infinite loops are a little hard to protect using asserts.
assert(is_tree(comment_graph))
Typically, a composite entity (like an "item" on HN which has many "comments") will define invariants to ensure data integrity. In this case, the invariant is that an "item"'s comments form a tree.
The database layer often contains this logic, but it depends on how you're building your application; NoSQL backends for example typically must put validation in the application layer. Since HN just uses files, a well-developed application layer should be riddled with invariants like this.