If anytthing the fourth week of 148 has been much like third. The concepts are still fairly easy to grasp and the exercises are still doable without too much thinking. This week we started our first recursion lesson. This was quite an interesting lesson (not just because the pretty pictures we made in class). Recursion proved to be a powerful tool in coding, allowing us to approach multi-layered problems with only a few lines of code.
Basically, recursion is the ability for code to call upon itself. This is useful if we want to have any branching behaviour, such as in fractals. However, it can be use for many more purposes. The example we did in class (aside from the colourful turtles), was finding the maximum of a nested list. We recursively called the function if the item we were inspecting was also a list, returning the maximum of the list each time. This allowed us to efficiently find the maximum.
In terms of the problem set for this week, I found it both challenging and amusing. The challenging part was grasping the concept of exceptions. In Java, we had touched on exceptions, but never in as much detail as we did in class. Wrapping my head around the multiple possibilities of exceptions took some time but I managed to finish the set within an hour. It is cool how you write a class for an exception. It makes it like an exception is its own class. The amusing part of the assignment was to implement the ValueError. The best way (or at least I could find), to satisfy this condition was to actually use a logic error in my code! I never thought in University of Toronto computer science I would ever be asked to purposefully hand in an error!
All in all, I think this week in CSC148 was an interesting week. I can only guess on how we will ramp up the difficulty from here!
No comments:
Post a Comment