Thursday, 30 January 2014

Week of January 29th, 2014: Exceptions, Assert, and a1

I'm super stoked for assignment 1; after reading up on the TOAH I've been curious on how to program the 3rd stage in such a way that the code can find the optimal solution, but I still have to look into that. Right now I'm supposed to implement the actual game loop, and while I understand and can visualize the control flow in  my mind, I am still somewhat uneasy calling things from the TOAH.py. But I hope to figure that out as it develops.

I also really liked this week's lab; unfortunately my partner and I got much too carried away with testing (we literally wrote tests for every possible case) and hence couldn't do the second half of the assignment, which I wanted to see as it also gave a more intuitive way to think of OOP. The definition on the open source website really fascinated me as it said while other programming languages write an explicit function/definition for things, OOP makes these a part of an actual class; for example in my kitchen I do not think of an individual "toast" procedure but rather conceive of it as a part of my toaster. For me this is somewhat shocking as I've learned all previous languages with a counterintuitive, somewhat 'untrue' conception of how to program and implement operations (in the sense that I see now reality is closer to OOP). So to see that Motorcycle class inherits from the original class was very cool for me, and it also resolved my previous problems with inheritance, classes, and subclasses. So again, it's a shame we didn't get to it ! We both vowed to ask our TA earlier next time.

In any case, I am also very curious to see where OOP implementation would be preferable to non-OOP implementation in the real world, especially in anything related to statistics or finance. From what I've seen, R is very popular for any economic analysis, while python's ability to handle text is very advantageous. But what about other applications, especially regarding big data ? I will investigate this as the semester goes on. 

Anyway, onto a1. Should be cool !

Thursday, 23 January 2014


Week of January 22nd, 2014: Queues, stacks, linked lists and general OOP

This week was fantastic. I was extremely fascinated in the runtime difference between queues and stacks during lab 2, as I have always been interested in finding the most efficient ways to compile/group/sort/extract information. The last section of the lab really stumped my partner and me, as we thought that queues took longer to work through due to python having to go through all the entries starting form the back; hence, as the amount of items in the queue grows it takes longer and longer to get to the front, whereas the stack run times seem to be about the same at every run. We tried to implement a "reverse" queue that would keep the front item of the first queue as its back item so as to provide quicker access for the dequeue function (so in effect, we ignore everything in the queue that wasn't the first or last item.) However, our TA told us that the run time wasn't increasing due to the amount of items growing, but rather because every time we dequeue an item, we have to "shift" the whole queue down. He suggested we look into linked lists, which provide adjacent references and thus allow the first and the last to be extracted quicker.

This is something that I really want to investigate further (even on my own time) as I'm now interested in when it would  be more advantageous to implement a queue vs a stack vs now a linked list. For example, if you need to extract something from the middle of the linked list, it takes even longer, so it isn't a ubiquitous solution.

I want to be super attentive to whenever we can implement either structure so that for myself I understand what the quickest way to get information is in any context. For the purposes of lab 2 I think the linked list would've been perfect, but I still would want to look into the reverse queue idea some time in the future. Even if it fails I'll still understand queues better.

Overall, a great week as I was also more comfortable using __init__ and defining classes (which I completely didn't understand last week). While I've done a lot of programming in the past, this is my first exposure to OOP so I am still learning the ropes. I don't have any problem running loop structures or understanding control flow/algorithms but the syntax has been difficult. Next lab I will try to be the driver specifically for the roles where classes are initialized and defined so I can get more practice !