3 ms·
I like thinking about variables as boxes with labels. Hadn’t heard that before, but seems like a simple way to teach people. I skimmed the description of recur
by mdonahoe 7y ago
I like thinking about variables as boxes with labels. Hadn’t heard that before, but seems like a simple way to teach people.
I skimmed the description of recursion. Seemed a bit long for my taste.
I was taught how to write a recursive function like this:
“Write the function signature, the docstring, and the base case. Then assume the function already works, and use it to implement the rest of the code”
- choeger 7y agoWhen you write recursive functions like this, you should keep in mind to get strictly closer to your base case with each recursive step (for some feasible definition of "closer"), otherwise you might never reach that base case.
- mettamage 7y agoIt’s how I teach people. I also think of variables as boxes and labels. Tje caveat is that for a non-primitive datatype, I put the address of a vault in the box and will go to the vault, everytime I use the value of the variable. I’m not talking pointers here, simply references.
- freetonik 7y agoI do a similar thing but with functions: running functions are boxes with labels, function definitions are blueprints of boxes. I use it in videos [1] to explain recursion. 1. https://youtu.be/vLhHyGTkjCs https://youtu.be/vLhHyGTkjCs
- tel 7y agoHeck, I still think of variables as boxes with labels.
- imron 7y agoIn some ways they are - they're just a little box of memory with an address.