|Friday 24th of November 2023 12:29:25 PM
I recently read an article about recursion and thought it was worth sharing here.
json-roller employs a lot of recursion in breaking down JSONObjects to simpler inputs. I think it would be almost insane to try and navigate a large complex JSON object without some form of recursion, unless you know the exact structure of that object.
However, this article kind of wags its finger at the idea that sometimes a recursive function can update a state variable that effects other calls to the same function. In json-roller, I know that the dataset is not going to change because the inputs are final before the applications starts.
In the case of "pivotJSONObject" I need to be able to throw information into a collection of Strings to track column names as each level of recursion hits different dead ends. This could be done as an object passed to each level and returned on the way back. So my point is, in my opinion, its not out of the question to have a recursive function return information to other parts of the program on its descent.