Saturday, 1 February 2014

Week 4

During this past week, we have been dealing a lot with recursion problems. In contrast to iteration, recursion, from what I understand, is a technique that involves the use of a function that calls itself in its code under certain conditions. That is to say, the function repeatedly calls itself until it is told to terminate; otherwise, the process becomes infinite and will generate an error. Recursion is very useful for condensing long iterating functions into very simple, short recursion examples, as the ones we saw in class.

One of the examples of recursion we saw since the beginning of the course was in determining the number of layers in a nested list of numbers. The function we created in class calls itself whenever a nested list is found inside a list of numbers, allowing for the prevention of the use of never-ending if statements in an iteration.

The most interesting thing we learned this week, in my opinion, was the Python built-in Turtle class, which allows Pythonistas to draw different line diagrams through the use of turtles that can create lines of different colours, speeds, directions and lengths. In this week's lecture, we were presented with an example of a recursive function called 'tree' with the use of Python's Turtle class. The function created three times as many different turtles, each at 120° from each other, as its level increased. As the levels would go up, three additional turtles would be created at the tip of each turtle created in the previous level. This resulted in a diagram that looked roughly like a triangular tree, with three different colours.

During this week's lab we were faced with more problems involving class creations; however, this time we were also expected to test our code utilizing unit test. This was certainly the hardest part of the lab, since I was not particularly acquainted with how to test functions using unit test and I believe it to be very hard in comparison to doc tests. Unit tests are especially difficult in my opinion because they require us to write our own classes in order for them to test our code, which I believe is very confusing.

The most challenging task in this week's lab was having to modify our unit test classes in a way such that it saved us effort by using inheritance to prevent code from being written twice. I found this very hard, since all classes had slightly different unit tests, and thus my partner and I were unable to complete this task.

No comments:

Post a Comment