Monday, 17 February 2014

Week 6

Week 6

This week in class, we went over trees. The terminology was straightforward and seemed logical (for example: root, leaf, node, path, length). How to write code that visits every element in the tree, called a traversal, was also reviewed. There were three types, pre-order, in-order, and post-order traversal, and each involved recursion. In addition, various methods for a tree class were introduced.

Outside of class, the thing I worked on this week were the lab and assignment 1. This lab involved list comprehensions as well writing some unit test cases. I remember that in the last time I had to do this, in a previous lab, I forgot how to do it and was a little confused. But this time, when I looked at the examples from the previous lab, the process was much more clear to me. The other part, converting list comprehensions to for loops, went okay. The other main thing this week was assignment 1. Although I thought I had finished it last week, I figured out that I could make some major improvements to what I had. This mainly applies to step five, which solves the Towers of Anne Hoy game for four stools in the most efficient way (hopefully). What I originally had matched the most efficient known method for up to nine cheeses. Starting with the tenth cheese, my method took more moves. By twenty cheeses, my method was using more than double of the best known method. (I found this out by looking at other people's posts on Piazza). To make matters worse, I did not see all this until February 13 at around 4:30-5:00 P.M. Luckily, I had about 5 hours to fix my code. After several failed attempts, I did figure out something that I believe produces the same number of moves as the best known solution for any number of cheeses (not just up to nine like my old method) with a few hours to spare. With assignment one out of the way, I guess now the thing to do is study for the midterm and start A2!


The first SLOG I randomly picked today is http://csc148minimalist.tumblr.com/. After reading this SLOG, I (and probably many people) can relate to this person in the aspect of “drifting in and out of classes in a zombie-like fashion” and hoping that this class would help ease me into the new semester. I do agree with this person in that the first lab was harder than I expected, and like I mentioned in a previous log, the directions were a little confusing. This person also makes a comment about CSC 108 being ego boosting, which I thought was funny. The second SLOG is http://heapofcode.blogspot.ca/. The first thing that stood out on this SLOG is the person's first entry title (with the def __init__), which I thought was creative. I also liked how this person tried to sound enthusiastic, and how he/she mentioned Pokemon in the Object Oriented Programming log because I happen to have a bunch of Pokemon toys that bring some very sweet memories back to me :)

Sunday, 9 February 2014

Week 5

Week 5

This week in class, the three stool version of Assignment 1 and names/scopes were reviewed in class. The three stool version of Assignment 1 basically showed how to use recursion in moving the cheeses, demonstrating the base case of one cheese, and the application of recursion for more cheeses. This seemed clear to me, and it was very helpful in doing step 5 of Assignment 1, where I had to solve the game for four stools instead of three. The second thing from class was names and scopes. This showed me the importance of using good, specific names for functions and variables. There were also no readings for this week. :)

The main thing I worked on outside of class was A1. After dealing with several problems, I think all I have to do now is run the pep8 checker. One issue I had was directly related to the names/scopes topic covered in class. In ConsoleController.py, there was a function called move. In my play loop function, I also had a variable called move. When I wanted to call the function move in play loop, I kept getting an error that said strings were not callable. I did not know what this meant at first, but then I realized that my play loop function was referring to my variable move (inside the function) rather than the function move (outside the function). This error was fixed by changing the name of the variable move inside the play loop function. Another problem I had was with Tour.py. When I first wrote my solution (and remembered to have a base case), I found myself in the “endless loop” situation. This took a while for me to figure out, but eventually I saw that I had mistakenly hard coded a value into the recursive part of my solution. After fixing that, and a few other small things, my solution worked, and I was relieved.


The last paragraph of my entry is the part where I randomly pick two other slogs to read. The first upon which I happen to stumble is http://c3reiner.blogspot.ca/. Like one of the slogs I read last week, this person has a background in another programming language. He or she (I don't know who this is) seems to think that Python is too simple in that its simplicity sometimes gets in the way of common practicality. Since Python is the only language I know, I don't have an opinion on this. But like I said in last week's entry, I am curious to see how other languages work. (Also, there is a funny picture of two lizards at the bottom of this person's entry (at least I think they are lizards)). This second slog is http://csc148slogss.blogspot.ca/. This person seems comfortable with Object-oriented programming. This person also found the directions for the first lab/tutorial confusing, and I felt that way too when I was doing the lab. And like me, Python is the only programming language this person knows.

Saturday, 1 February 2014

Week 4

This week, the topic introduced was recursion. It seems to me that the basic idea is to call a function within itself (with a base case so the recursion does not go on forever and result in an error). The pictures generated using turtle in class and in the readings looked nice, and it made the topic seem more interesting. So far, I understand the examples in class, but as usual, I feel that I need to do some practice on my own before I can feel confident about recursion. Also in this week's slides was something called lambda. This was not mentioned in class (maybe it will be next week), but I did see it in the code for GUIController in A1.

Outside of class, there was the weekly lab, exercise 2, and A1. During the lab (about inheritance this week), the hardest thing for my partner and me was not actually the inheritance itself, but writing the test cases. Writing unit test test cases was something introduced in CSC 108, but I did not get much practice there (so I should probably get some more, perhaps by trying to write some for A1). The second thing this week was E2. This exercise went smoothly for me in general; I did not have that many problems, and I managed to pass the autotester. The last thing this week was A1. I only started it this week, and did not get very far. Something I noticed was that I did not have the module tkinter, which I thought was odd because Python 3 normally comes with that module. This problem was quickly solved by manually installing it.


 Last, I randomly picked two other SLOGs to read. http://achievementsuperlog.blogspot.ca/ was the first one I chose. This person seems to feel relatively comfortable with Object-oriented programming. This person has had previous experience, using the language Java. I thought this was interesting because once I learned Python, I have always been curious about how things are done using other languages. (Also, my high school had a programming class using Java, but I didn't take it.) The second one was http://asdfghjklasdfghjklas.blogspot.ca/. This person wrote about how Object-oriented programming was like an organizing tool. The person also mentioned about the problem with fancy toy in E1. I also had this problem even though I did not hard code strings like 'Squeak!' into my code too, but I figured out how to solve it. For a side note, when I read other SLOGs, I usually read the most recent entry.