Sunday, February 9, 2014
Recursions and Namespaces
This weeks focus has been on tracing recursions and namespaces. The lab was mainly on recursions, and we traced several different examples. It wasn't too difficult to trace, if you picture each call of the function as a branch and the output as the leaves. The more calls, the more branches that grow, the more leaves. We also look at namespaces and the scope in which a names and variables exists. I think the corresponding names sort of sums them up. Global, non-local and local, all give an idea of where the variable will exist. I found this useful in one case in assignment 1. Where I wanted something to be done only once, in a recursive function. So I created a global Boolean variable which I used for a condition, then changed it afterwards. Since, it was not in the scope of the function, it wouldn't not be changed back and forth from True to False, but rather start as True outside of the function, and only change to False within the function. At least that's how I view it.
Saturday, February 1, 2014
Introduction to Recursion and Exceptions
This week, and the last, the main focus in class and the labs have been on recursion and exceptions. Both of which are something that I have not done in high school, so I've finally met something new. The one line recursions are a bit confusing to try and dissect. I'd prefer if it was separated into more lines, but It may just be a lack of experience. The recursion involving the writing turtle was very neat, and not at all hard to follow. Recursions are basically a looping function, with a base case to finally stop it. Exceptions are even easier (so far). In our lab we wrote our own tests for a class and it involved an exception. The lab was a bit challenging, but was very helpful in understanding the material. It also helped with exercise 2 which involved creating a function and then a tester for it.
Subscribe to:
Posts (Atom)