“Flat is better than nested” - for data as well as code?

前端 未结 6 389
不知归路
不知归路 2021-01-31 16:05

This question got me thinking: should we apply the principle that \"flat is better than nested\" to data as well as to code? Even when there is a \"logical tree structure\" to t

6条回答
  •  北恋
    北恋 (楼主)
    2021-01-31 16:26

    I wouldn't inherently prefer either, but rather use whatever seems best suited to the task.

    If the structure is important, nesting makes life simple. If you're regularly operating over each node, the flat structure makes it easy to use for node in tree. Of course, if you define your own class, its easy enough to abstract it so both options are simple; but it may be harder to use with external systems, such as converting to JSON.

提交回复
热议问题