The first one is: don't ask monks on mountains for stories. Trust me I've been there, they make you pay and it's a waste of money.
The second one is, this entire story is a metaphor for recursion (albeit a badly written recursion).
To expand on this over stretched metaphor, recursion is a feature in programming that occurs when a function calls itself, like we see with the monk and the story. Now in real world, recursion is actually a lot more useful and less banal then what you see in this story. A good example of when recursion is awesome is factorials.
As my friend Lindsay had explained and shown in her slog entry, the use of recursion opposed to "normal" coding is more efficient. From her example code, you can see that the use of recursion saved 4 lines of code.
The main downside of recursion, however, is that it takes up more memory and time as you're taking up more stack frames opposed to loops which clears the stacks in each iteration. Also, recursion isn't the easiest thing to wrap your head around it.
In my personal opinion, I don't believe recursion is terribly useful. I feel that saving memory space and time is more important then the elegance of a code or saving lines. Furthermore, it's very easy for one to write a recursive function that may never stop if they don't have full understanding of the recursion.
This connects to the third moral of our story, if you're writing recursion, make sure you write an exit.
Imagine if you will that the story never had an ending, that the original monk just kept talking about boys, monks, mountains and houses. Then the original boy would probably looks something like this by the time they get to the nth monk in the story:
And that concludes my long drawn out metaphor.
TLDR:
- Recursion is a function in programming that calls on itself
- It is a good alternative as it can shorten code lines
- Recursion often takes up more memory and time then normal loop methods
- Lest you want to sit around for something that never ends, one should always make sure that their recursion statement has an exit
Monks need better story telling skills


No comments:
Post a Comment