4 ms·
Finding out how to traverse a tree recursively was one of the first great “aha” moments of learning CS.
by gallerdude 7y ago
Finding out how to traverse a tree recursively was one of the first great “aha” moments of learning CS.
- tombert 7y agoAbout two years ago, I had to (sort of accidentally) create a DSL out of JSON that emitted SQL. My first attempt was trying to hack something together with a bunch of arrays and hashmaps, but I realized that since there's no real "limit" to how nested SQL can be, that that wouldn't work. I scrapped what I was working on, and started over, fully utilizing recursion, and it led to substantially shorter code, that didn't perform measurably slower, and let me handle the full SQL spec correctly. Sadly, I moved off that project, and the person who inherited it didn't understand recursion very well, and rewrote it without recursion, and ended up making it not able to handle the full spec.
- howard941 7y agoAbsolutely! As a thought exercise, what sort of non-trivial tree traversal is possible without recursion or looping? I do use recursion quite a bit but always honoring the JPL coding rule (I can't find it) to put some form of safety fusing in recursive code to avoid inadvertent stack blowouts.
- lincpa 7y agothe Pure function pipe data flow completely conforms to the JPL coding rules. [The Pure Function Pipeline Data Flow](https://github.com/linpengcheng/PurefunctionPipelineDataflow https://github.com/linpengcheng/PurefunctionPipelineDataflow)