Monday, February 2, 2015

Week 1-3 Impressions

In the past few weeks, we've gone over things like defining __repr__ for classes, inheritance, list comprehensions, abstract data types, and just classes in general. What I've found most interesting has been list comprehensions, and what accompanies that interest is a sort of mild frustration. Why did we not learn these earlier, like in CSC108? When I think over all the code I wrote for CSC108, so many lines could have been saved if I had just known about the existence of list comprehensions. However, I'm sure that the instructors had a good reason for this delay. One possible reason is that using 'for' loops and the 'append' method is a good way of practising more elaborate code that can't be done with list comprehensions. Also, I know (based on a quick Google search) that list comprehensions are not universal (for example, Java does not support them). So, the loops that we used in 108 are more applicable to other languages, and the fundamentals of programming. (Despite these reasons, I'm still somewhat irked.)

Another highlight of the past few weeks has been, of course, assignment 1. I cannot deny that I enjoyed doing assignment 1. I read the handout one evening, and then was so engrossed in it that I accidentally stayed up until 4am to finish the bulk of it (thankfully, it was a Saturday evening). When I was done, I got my (non-CSC148) friends to play Subtract Squares, and tweaked the game view until it fit my standards of visual appeal. Assignment 1 passed without too many major problems. I missed a lot of brackets, and had to fix those many times. There was one point where my report_win method in the GameView class kept claiming that the computer had won, and the problem with that method happened to arise from a problem in another method in my Game class, so that was a bit painful.

The most interesting problem arose from my choice of letting the user determine the upper random number limit. My friends tried to 'break' my program by setting numbers like '123123123123123123123123123123123123123123' as the upper limit, and (un)fortunately, they succeeded. The following error message would appear: "builtins.OverflowError: Python int too large to convert to C ssize_t", so my obvious response was to add an 'except OverflowError' statement to my input line. Yet, the error message would still appear. After much deliberation, one of my friends suggested that perhaps it was the code several lines afterward, rather than the input statement that caused it, and I looked into that. It turns out that the list of possible moves that arose from such a large number was too large, and that was what caused the problem. So, I fixed my code with an 'except' statement in the right place.

CSC148 has been great, and from what I've seen of recursion so far, it will almost definitely get more interesting.

3 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete