Sunday, March 29, 2015

Object Oriented Programming - Revisited

Well, this is a first for me but today I can say with happiness that I am DONE the third and final assignment a full 5 days before it is due. After implementing the functions last weekend, I've been focusing on debugging all of this past week with the help of my partners, and our code now passes all of the doctests. Now we are merely finessing the style. This is the best feeling. It's a shame that I couldn't have gotten this on top of things in time for A1 of this course, or even A3 of 108, or better still, A1 of 108! Ah well.

Anyways.

The implications of OOP for recursion

I am going to revisit my blog post on object oriented programming. I still think my bare-bones summary of object-oriented programming stands - it was correct, if a bit brief. However, what I didn't go into in that summary was the implications of using object-oriented programming.

It is really, REALLY convenient to get to treat a function as an object (specifically, as the object that the function returns). Specifically, this is convenient when it comes to recursion. This is something that really hit home when I was trying to write the grow() method for class GameStateNode (this being a recursive function that alters self directly and returns NoneType). Not being able to treat the method as an object really threw me and I can only imagine how much weirder it must be in non-object-oriented languages. I ended up figuring out a way to do it that works, but I'm not sure if that's the "proper" way to do it - afterwards, I was discussing it with a classmate and that classmate said I should have just made recursive a helper and had the helper return an object. At this point, however, I had already spent hours getting my code to work and I wasn't about to steal this classmate's idea, so I just left my code as it is. That classmate's idea takes fuller advantage of the object-oriented structure of Python than mine does, which is probably good. My function, on the contrary, is something that I think theoretically would require less changes to rewrite in a non-object-oriented language (in some hypothetical world where I know other languages than Python, of course).

Understanding the bare-bones components of object-oriented programming (objects, types, classes, instance variables, global variables, methods versus module-level functions, et cetera) was interesting and certainly informed my ability to complete the assignments and succeed on the tests this semester. On the other hand, it is thinking about the implications of object-oriented programming that actually makes me curious to the extent that I want to learn more languages. I mean, I only took 108 and 148 because of their being requirements for my Cognitive Science major, but now I must say the thought of taking 207 just for the fun of learning another language has certainly occurred to me on more than one occasion.

Sunday, March 22, 2015

Update (not main post for the week)

This is my second post this week. I think the first one should be marked rather than this one since it was more detailed than this is going to be. However, the first one was a little pessimistic so I thought I'd add on this one as a happy update: I have been unable to sleep much for the couple days since I made that post and so because of that I have tackled all of the part B functions and implemented most of them! Yay! :D

Figure 1: Trees are growing on me (no pun intended).

Now to debug.

Friday, March 20, 2015

Impressions of week 9

Week 9

Week 9 has left me extremely frustrated. Specifically, frustrated with A3. Actually, no - frustrated with A2 AND A3. We were given a unittest with which to test our minimax programs on subtract square... I made my own unittest before this week's lecture (since I'm in the wednesday evening section) and so was not aware of this, and wasted quite awhile fussing with my unittest. Then, as soon as I ran the one the profs posted on my code, it FAILED. SPECTACULARLY. As in, it didn't just fail one of the tests, it failed HALF OF THE TESTS. Of course, I don't know as of yet how badly this has affected my A2, but my imagination is going wild.

Meanwhile, I was getting an early start on A3 and had chosen part A (the part that relies on a successful minimax) and - get this - I had already IMPLEMENTED an entire section of part A. Of course, that doesn't matter because it was just adding on to a flawed program, which means it would have failed too. What's the point of optimizing a program that doesn't return correctly half the time?
Anyways, now I'm going to do part B. Which means the time I spent implementing one-third of part A was wasted. 

Okay, that's pessimistic. The time I spent a) making my own unittest and b) implementing part of part A (albeit as an extension of a flawed function) was not WASTED per se. I mean, if I want to take a completely narrow, short-term, results-oriented view, then yeah it was wasted, but in all reality, this way I know more CS! Even if my mark will not benefit from me doing that extra work, my knowledge will. So there. (I may or may not simply be trying to convince myself of this.) No, seriously. Task-orientation > ego-orientation. Learning is good. In the spirit of that, let's focus on what important CS concepts I did learn from all of this (or, specifically, one concept which I became aware I do not know as well as I thought I did).

Lessons that can be drawn from all of this: 

If my code failed the unittests but passed my doctests, this is not just some fluke, it's representative of an underlying problem: apparently I suck at coming up with test cases! This is a serious problem, and one I will seek to address as I work on A3, and completely solve by the time I get to the exam. I do not want to repeat my mistakes. I will address this problem by reviewing 108 material on how to choose test cases, and even review some 108 past exams yet again (I did past 108 exams in order to study for my own 108 exam, and recall that test-case-choosing featured prominently on them). 

Ironically, now that I think of it, although I did quite well on the 108 exam, the one question that completely stumped me was this small, innocuous-looking 3-mark question about creating a single test case that would demonstrate the flaw in a given implementation of a function. I don't even remember what I put, but it was a guess and I certainly don't think it was right. I don't remember the specifics of the question now, but the fact that I had to guess and didn't feel like I was even close to grasping what it could be should have prompted me to study test cases over the holidays. I did not study test cases over the holidays. In fact, I did not open IDLE from the day of the 108 exam until the day this course started. Embarrassing? Yes. I can't change it now, though. I can just go back and revisit those sorts of questions yet again, three months later than would have been appropriate. 

Friday, March 13, 2015

Thoughts on Week 8 and T2

                                              Figure 1: Every student at some point in life

Midterms. Collectively, they make up an experience that often evokes the response depicted in Figure 1, especially by the time March rolls around. All of which goes to say that it is an absolutely wonderful feeling to finish one's last midterm of the 2014-2015 school year with a) the sense that one has done well on it and b) the unrelated but equally pleasing surge of energy and optimism that comes with dramatic temperature increases like those of this past week. "All's well that ends well", right? Right. Let's go with that.

In any case, here are my thoughts on Week 8!

Part one: good things

1. Firstly, I find it really interesting how CSC148 is organized, deadlines-wise. Less than a week after A1 and A2 were each due came Test 1 and Test 2 respectively. This makes it impossible to a) become complacent in the wake of a smooth-sailing, successful assignment or b) avoid thinking about the course for a little while in the wake of an extremely unpleasant assignment-completing process. As soon as we've handed in those assignments, we had better be studying. While on the one hand, I find this a bit annoying because both a) and b) have been very alluring options for me at times, I also enjoy the fact that CSC148 leaves no time for lollygagging. If you had a bad assignment, you can't just go "well, I'll make my comeback on the midterm... but first I'm going to have a bit of down time". You have to rally immediately if you want to make that comeback. Same goes for if you did well on the assignment and want to continue to do well - there's no time for thinking about doing well, you've just got to do it. As someone who usually stresses myself out over-thinking things, I find this aspect of the course (whether purposely done this way or not) to be very helpful. I definitely responded better to this pressure this time than last time in terms of stopping thinking about the assignment and just sitting down and studying, so that's something I improved on from Test 1.

2. I really used the aid sheet to its full advantage this time round. The first midterm, I didn't really know what to do with the aid sheet since I'd never had an exam that permitted them before, so I didn't use it to its fullest potential and barely even looked at it during the exam. This time, I asked advice from other students as well as profs about what to put there, and I kept notes on what would be most useful to me. Then, writing really tiny, I wrote the most lovely aid sheet ever. First, though, I divided the page up into small boxes, and used this visual method in order to make sure I knew where exactly everything was going to be, so I wouldn't waste time finding it on the exam. It helped SO MUCH. So this is definitely something I learned during T1 that I was able to apply come T2. 

Part two: what I want to improve on 

1) Especially with the Linked Lists, I found it very helpful in office hours when the professors drew pictures, but when I drew pictures I usually ended up confusing myself. I ended up being able to reason my way through LL problems just using overly-commented code and walking myself through it like that, but I want to be able to get the full benefit of picture-drawing by the time the final rolls around. 
2) Also, I want to review the way people draw objects to show their memory addresses. I think my understanding of both LLs and memory addresses will be enhanced by actually being able to draw it out rather than just describing it in words and picturing it in my head.

TL;DR: in the future, I want to draw more pictures.

I will leave off with this screenshot. I was doing past midterms and I found this on the front of one of them: 


Figure 2:
That moment you realize not everyone thinks students are numbers! Hooray!

D'awwe!
Also! Re: the "a number doesn't define you" - in general, I've found the CS community to be awesome in terms of not treating students like numbers. As a life sci student accustomed to having the majority of my classes in con hall, I really appreciate this. 

Monday, March 9, 2015

A2 stress and other fun stuff

This is my Week 8 SLOG. Sorry that it is one day late; if I get a zero on it because of that, no hard feelings. I'm going to write it anyways though, so either way it will sit here on the internet, collecting internet dust, passive-aggressively yearning to be read and maybe even given a non-zero mark.

Kidding, kidding.

Week 7, in a nutshell:

1. While doing A2 I learned a huge amount about the actual application of recursion-related concepts we've been learning for the past month.
2. I also did not sleep very much. On top of A2 I had to prepare and give a research poster presentation for another course, as well as writing a midterm.
3. I'm not going to pretend that anything else really happened CS-wise during week 7 apart from working on A2, at least for me. The lab was cancelled, so I didn't do the lab. I didn't even start studying for the midterm until after handing in A2, which is probably bad but I couldn't have imagined doing it any other way... which is also probably bad. That's awkward.
4. At one point, there were so many students crowded around the outside of Prof Horton's office for office hours that other profs came by and asked if this was some new "Occupy Bahen" movement.
5. I am so very glad I got all my code written sooner than I did for last assignment, since the debugging for this assignment took WAY, WAY longer. Everyone who has ever said that recursive code has a much bigger potential to go wrong than non-recursive code was VERY RIGHT.  So basically, I learned my lesson from last assignment and did finish my code earlier, but still ended up stressed out with eleventh-hour debugging escapades because of the sheer amount of debugging that had to happen this time round. Oh well - if I *hadn't* learned that lesson, I would certainly not have gotten the program to run in time, so I am profoundly relieved that I did.
6. These items are getting a little run-on and self-indulgent (who ever heard of a blog being run-on and self-indulgent? hardy har har) so I'm going to separate the next bit into categories kind of after the style of a debugging journal.


Notable bugs experienced:
1. Ok so my recursive function was structured so that if the depth required to actually return a value that made sense was greater than a certain pre-determined value (self.depth, incremented each time the function recursed), the function would randomly choose a move. However, there was a problem with that such that the random move wasn't actually random, and this took me awhile to realize, because at first I thought "OH, THE RANDOM MODULE'S JUST DOING A BAD JOB."
Lesson learned: When the problem could be a builtin module, or could be your code, it's probably your code. Don't give yourself the benefit of the doubt.
Outcome: Eventually I fixed this bug. The day the assignment was due. It was intense but it worked out. However, it wouldn't have been that intense if I'd not given myself the benefit of the doubt in the beginning.

2. Five letters in one line of code in one method (apply_move) meant that our grid was never being updated when the players made moves. This was very stressful, as might be evident.
Lesson learned: Before angsting about code not running, READ THROUGH EVERY SINGLE LINE OF THE METHODS BEING CALLED ONCE AGAIN, and check for stupid, stupid errors.
Outcome: Eventually we found it, by doing the above. However, we could have solved it sooner if the above had been our initial response rather than wringing our hands and panicking. :-)

3. This isn't really a bug, but it resulted in bugs: I used too many helper functions for minimax, and it got really really confusing, just logic-wise.
Lesson learned: The simplest solution is best.
Outcome: I went to see Prof Heap in office hours, and he told me as much (the simplest solution being the best, that is), and I fixed the code. However, this was a bit inefficient because all in all, my partner wrote 1 version of minimax followed by me writing 4 subsequent versions of it before it actually made any sense. All part of the learning curve, I realize - and our understanding has greatly improved over the past 2 weeks. However, the lesson learned is still a good one to bear in mind.

... Now, obviously more bugs than this occurred but these were the three most memorable issues in our process.


My computer has 2% battery left, so I'm not going to write about my midterm studying process; instead, I'm going to actually go study for the midterm. Toodles.