Tuesday, February 17, 2015

Week 5: Object Oriented Programming

Building upon our understanding of object oriented programming and revisiting some previously covered concepts, week 5's material took a closer look at the implementation of classes and methods, particularly in the context of recursion in the tree structure - tree.py. Here, we first defined a number of functions including __contains__, leaf_count, and decendents_from_list, and eventually promoting each function to a method of the class object Tree.

I feel a couple of new items worthy of highlighting include:

a) copy(), a built-in function of python
b) the syntax and use of if and else in the examples of init and repr:

     def __init__(self, value=None, children=None):
self.value = value
self.children = children.copy() if children else []

&

    def __repr__(self):
        return ('Tree({}, {})'.format(repr(self.value), repr(self.children))
            if self.children
            else 'Tree({})'.format(repr(self.value)))

Classically, we were taught that if and else should begin at the start of a statement, otherwise we would usually return some form of a syntax error. Here we see the exact opposite, and it works! It seems as though we're breaking more and more of these once arbitrarily defined rules. May be they were constructed as a way to help us understand the basics without having the confusion... Is it just me, or is python starting to feel more obscured?

I'm also beginning to appreciate the complexity of using an array of functions within functions or methods, rather. I shamefully admit that this took me way too much time to understand.


def descendents_from_list(t, L, arity):

    q = Queue()
    q.enqueue(t)
    L = L.copy()
    while not q.is_empty(): # unlikely to happen
        new_t = q.dequeue()
        for i in range(0,arity):
            if len(L) == 0:
                return t # our work here is done
            else:
                new_t_child = Tree(L.pop(0))
                new_t.children.append(new_t_child)
                q.enqueue(new_t_child)
    return t


As an aside and a final note, assignment 2 was posted recently and for those trying to get a better grasp of minimax, I found a good resource to read up on: http://neverstopbuilding.com/minimax. Cheers.


Monday, February 9, 2015

Week 4: Recursion

Last week's material (or two weeks ago, rather) examined some of the basic concepts of recursion, focusing on tracing through various elements and nested lists. I was intrigued by the concept of a function able to call upon itself repeatedly through any level of complexity, and admittedly, skeptical when we were first presented the example sum_list in lecture.

While we have yet had the opportunity to write recursive code in depth ourselves, the tracing exercises in lab have been greatly helpful in better understanding the principles behind recursion, the use of base cases and the way in which it influences the overall output and function. I am still having some difficulty implementing recursive code, but hope to have this down with a bit more practice in the coming weeks.

Monday, February 2, 2015

First Few Weeks of CSC148

Four weeks in and I am definitely still trying make sense of some of the course material, hopefully in time for our first midterm this coming Wednesday. Before taking CSC108 in the fall, I had little next to no computer programming experience. While I am enjoying CSC148 so far, it is a different format than what I have been accustomed to. I feel as though there is a bit of a leap between the two courses. Either that, or there is undoubtedly a gap in my knowledge base. Maybe it's both.

Week one, we jumped right into object oriented design, barely glossing over any of the fundamentals. I guess that part was assumed, not that I'm complaining, of course. Week two and three, I'm starting to get a better idea of class implementation and inheritance. I'm also starting to understand the importance of starting labs ahead, and using my time effectively for questions and feedback. Something I feel is just a tad lacking.

Perhaps I'm the only one, but I miss the detailed explanations and exercises we were able to slowly walk through in each week's lesson in 108. I miss PCRS, the videos, and the the instant gratification of knowing whether my code passed or failed. Above all else, I miss the structure. Although, I appreciate having the lab setting is extremely helpful in meeting other classmates, and certainly provides an invaluable opportunity to interact with the TAs face to face with questions, it just hasn't been quite the same. I guess what I'd like to express is that CSC148 is different. It's different in that it requires a higher level of independent learning and initiative to get the feedback you (read: I) need.