Re:What if you couldn’t program with loops?
by gallerdude on Monday July 15, 2019 @09:57AM
(#20440842)
Finding out how to traverse a tree recursively was one of the first great “aha” moments of learning CS.
[ Parent
| on HN ]
About 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.
Re:What if you couldn’t program with loops?
by howard941 on Monday July 15, 2019 @10:43AM
(#20441257)
Absolutely! 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.
the Pure function pipe data flow completely conforms to the JPL coding rules.
[The Pure Function Pipeline Data Flow](https://github.com/linpengcheng/PurefunctionPipelineDataflow)