Sunday, February 9, 2014

Week 5

The classes this week once again focused on recursion, but also on the new topic of namespaces and scope. We learned that there is a hierarchy for namespaces that python searches through to use:

  • innermost scope (function body, usually) local
  • enclosing scopes nonlocal
  • global (current module or __main__)
When python is searching for how to perform an action, it searches through this list from top to bottom; if it finds a local solution, it will not use a built-in for example. This can be useful for if you only want to reference something inside a function or clas, while also having it perform a different action outside (or at least, that's what I think it's used for). Going through some other SLOGS, I found many other students have had trouble of tracing the code example of namespace presented to us, and I agree that it went a bit over my head initially. However, now that I have had some more time to analyze it, it seems a bit clearer to me at least.

The lab this week was, well, average as usual. We programmed simple examples of recursion, and I can see now how applicable it can be in large situations with similar problems. Speaking of which..the A1 deadline is approaching, and for (my partner and I) at least I think it is going well. The recursive four stools function looks a bit daunting, but given the move_cheeses example that Prof Heap gave us it seems a bit more manageable (I hope!).


No comments:

Post a Comment