Having said that, I cannot wait for tomorrow. Marcus spent a good time today differentiating between the different strategies we could employ to rewrite a basic version of a very popular browser-based recursive function, using the analogy of telling classmates to write down the names of those around them wearing red shirts on a notepad:
- telling each classmate to write the names on a public notepad is akin to storing your recursion results in a global var, which means that you can only call the function once before having to instantiate a new var or clean out the old one.
- Marcus creating a notepad and passing it to the first classmates (to be passed along afterwards) would be like creating a top level var within your function and calling a subroutine to do all of the recursion (my previous preference and go-to strategy).
- The third has each classmate write their own notepad of names and pass the notepad up to the classmate who passed the instructions, concatenating them with the caller's notepads every step of the way until you get to Marcus, who just returns the notepad. It took me a while to finally wrap my head around it (which is not to say that if you asked me to write this tomorrow, I would do it successfully), but I think I have a much more solid grasp on recursion than at any point in the last year, so there's that.
Hopefully that made sense but if it doesn't, well whatever, its 11:13PM after my first day and I'm tired as hell.
No comments:
Post a Comment