Thursday, 26 March 2015

Reflections

Building Up and Looking Back:


This week, I'll be looking back at a post I wrote, and examine how I could improve upon it, and how my views of the course of changed. 

Due to that, I'll be reviewing my post that deals with troubleshooting, seen here.

I chose this post, because it represents a skill that I think that will always be useful in this discipline.(even if we don't do it in the way I described in the course.)

So, in that regard I would agree with past me. I would disagree with past me in that printing every step of the way is an efficient method later on when we're throwing large amounts of data around. 


When you have to slog through that much data to find one small error, and then go find the code that produced the wrong result, and then spend a ton of time trying to bugtest? It's horrible! 

(Interestingly enough, while printing a play-by-play is effective for small problems, it becomes much worse the more complex the code you have. It's like Big O!)

That's why another post of mine, last week's post on doc tests is the other article I'm going to reference. The doctest post, in theory, is quite similar to my older post on troubleshooting. 

However, if each function has a doctest, it's very easy to figure out where a problem is localized, since upon running we're given a notification saying where the issue is. 

It's quite interesting, since this is the biggest part of learning; adapting the old things you knew, and refining them for future usage. I feel like my classmates would all agree on that, regardless of what post they're comparing or what knowledge they're comparing. 

Friday, 20 March 2015

"I said Assertive, not 'Insertive'!"

Jokes aside, this week we dealt with an important part of software engineering; maintenance.

For our own personal one-person projects, we don't have much of an issue. We know how our code works, what it does, and the logic behind what we did.

However, if we have a long, complicated project, or multiple people, or we're revisiting an old project of ours, we may not remember (or even know!) what the function does, if it even works, and if our changes or modifications will make or break it.

Previously, we had comments to explain certain things to outsiders in our code, but comments won't save us if we tweak an algorithm, and assume it still works.

Thankfully, we've learned an incredibly useful operation this week; "Assert".

Assert is, as the name implies, an assertion. While niche in itself, it's extremely useful in something we've seen a lot in our CS career so far at U of T: Doctests.

When writing a function, our style of commenting has us write a docstring before each function, including an ideal situation that shows the output for a successful implementation of the function.

Assert lets us test this; if we assert that function foo() will return "bar", and foo() doesn't return "bar", then when we run it, we're given a reminder that our function didn't pass our test case. Our syntax may be right, but our logic may have flaws in some places.

Assert (as we've learned it) will allow us to catch issues like that, to make our code all the more organized and well-running.

Tuesday, 17 March 2015

Deepcopies!

This week, we discussed the finer points of things we were supposed to learn while coding assignment 2. One of these was deepcopying.

When you normally create an object in Python, you essentially give a 'name' to a reference to some object. So, when people write "a = 6", whenever the computer sees "a", it follows the pointer to the value 6.

When people want to create a copy of "a" (let's say it's "b"), the computer saves space by simply copying the reference. So, when the computer sees "b", it goes to "a", which goes to "6."

If we change "b" to some other value, it's not a big deal. However, if we change "a" to some other value, we unintentionally change "b" as well, since "b" isn't a unique value, it's simply a reference to "a". If "a" changes, "b" does as well.

Obviously, this can serve to be quite the issues. Sometimes, we need to manipulate an object, without messing with any copies of it we have created. This, in turn, is why we have deepcopy.

In reality, deepcopy is what a human would think of as a copy. However, in a large program where we may have hundreds (or even thousands!) of objects, and an equally large number of copies of these object strewn about, it can start to become very inefficient to have new memory allocated every time we want a new reference to an object.

However, sometimes we really do need that extra space, and as such, we need to distinguish it with a proper function. This in turn saves space and runtime, while still not constricting us in any sort of way.

Friday, 13 March 2015

BST Reflections

This week, we covered Binary Search Trees, as well as inserting and deleting information in them.

Binary Search trees are a way to recursively store data, as well as fetch it in an easy and elegant manner. They're similar to Trees (as the name implies), but they're only limited in scope to a maximum of two children.

Compared to Trees, I personally find these a lot more easier to navigate and work with, but due to the hard limit of only two children, it makes the application very limited in scope.

My issues with Trees continue to be working with variables or lists that have to travel between the recursive layers. However, as I continue to do the exercises, it's slowly starting to make sense.

Thursday, 5 March 2015

Reflecting on Assignment #2

Assignment 2, what could have been.


Full disclosure; I did Assignment 2 totally wrong. Taking from my code I created for A1, I got about 70% through the assignment before I realized we were strongly recommended to use the starter code.

Given that 1. I found that out three days prior to the due date, and 2. My design of the classes was very different than what were given, so recycling code was out....You can tell how the rest of this week went.

Given that I had three days to do it, I spent all 3 days pulling long nights, caffeine fueled benders, and 20 tabs on python tips perpetually open.

In retrospect, it's taught me a few things, as well as given rise a few questions I've had as well.

What I learned:

  • Procrastination never pays off.
  • Learn the tools and framework you're going to use before you actually need to use them.
  • Recursion is scary.
As for future questions, my prior framework that I ultimately ditched in favor of the start code used "Player" objects that came with some methods that would've made my life a lot easier. In addition, I used one GameState that simply updated as time went on. 

In my mind, this was a pretty logical and intuitive way to approach the problem. Next week, I'll be visiting both professors to inquire about the design choices, why the decided to structure the code like that, and how that is more advantageous versus my original method. 

In addition, given that the code I turned in was extremely buggy (although, it was in on time!), I'm ot exactly expecting to be heralded as the next Alan Turing, so I hope I will survive grade-wise.

Will update this post with the advice given to me by the professors when the time comes. 

Wednesday, 18 February 2015

A2 a go-go

The recursive tree must be refreshed from time to time with the sweat and tears of first-years


Updated Thomas Jefferson quotes aside, this (and last) week we saw the emergence of our first real practical application of recursion; Trees.

Trees are a relatively simple concept, in theory. Organize information in a neat and elegant way, and allow us to fetch the relevant information as well.

In theory.

In practice, it's been something along the lines of techno-wizardry, something we type in and somehow it works.

And now, we actually have to understand it to use it in A2. Lovely stuff. Looking at the assignment, it doesn't seem to be too difficult. There will be moments where I'll need to rewrite my source code in order to accompany multiple games. However, that doesn't seem to be too hard. The hard part will be tidying up everything.

Having taken a slightly different approach to the class structure in A1, I'll need to think long and hard about how I'm going to reconcile everything. That being said, I'm looking forward to the challenge, and not looking forward to the caffeine fueled late nights. 

Tuesday, 3 February 2015

Eve of the midterm

T-Minus 10:30 hours

Sitting in the Burwash common room as I write this, I've decided to reflect on the process I've taken along for studying. In this week, I have both the the examination in this class, and in my psychology class. The difference in how I went about studying was pretty apparent. 

In psychology, I went about sheer memorization, being able to recount information at a moment's glance. 

That doesn't seem to be the case for CSC148. CSC148 is unique in my course experience, because the amount of material we have to memorize is comparatively low, but they key is not in knowing how these things work, but in how we can apply them;

Last semester in CSC165, I had tried to study to simply 'learn' the facts. That resulted in me spending about 20 minutes on one question, and attempting to finish the other 2 in a flurry of bad logic and messy handwriting.

That was not the right way to go about that problem.

Hopefully, I'll be able to do it better this time. 

Wednesday, 28 January 2015

The wonders of retracing your steps!

As I'm procrastinating on finishing up A1 right now, I've realized something very, very useful we haven't really touched upon in class. (Or, if we had, I was too busy nose in computer trying to fix A1 since I didn't know this, so.)

As we move on to more and more complicated assignments, we're forced to step back and look at the big picture. Suddenly, we have to think "are the parameters I'm sending to this function really correct? The function may be okay, but if the input is bad, the whole thing can appear wrong."

This is why tracing is important. I'm sure everyone has a word they use and definition they use to describe this, but in designing and test A1, I personally put in print statements at the end of every function. In doing this, I can follow the various lists, numbers, and strings being sent to and from my game state at all times. In doing that, I can follow where everything was going, and when I do spot a mistake, it takes only a few minutes to spot and fix.

Only issue?

I figured this out after 2 weeks of old school debugging.

Monday, 19 January 2015

Why Geeks Should Write:

Being well-rounded is pretty swell.


Since the dawn of man, humans have excelled at messing things up. This is not an insult, it's actually quite the opposite; To make a mistake, that would imply you would have had to do something, to create something to mess up. Given the astronomical amount of mistakes in human history, that speaks volumes to the amount of things we've achieved! We've messed millions of things up! Millions of things we built! Monument to our sins, indeed. 

It's in this dreadfully deterministic line of thinking that an individual blessed with a rather large amount of common sense came up with a novel, yet genius, way to prevent at least some of these mistakes.

Record keeping.

You see, every so often an individual comes along that prefers the company of books and his own mind rather than the outside world, and those sorts of individuals enjoy fixing problems. This is a geek. Geeks are pretty smart guys. However, geeks are still human, and are still prone to making the same mistakes as the rest of us. 

Wouldn't it be great if there existed a collection of the mistakes that others have made before? Perhaps, dare I say, with some commentary on it? On what the previous geek did wrong, and what their thoughts on the matter was? Perhaps to expedite the process of the new geek, allowing them to work further than anyone before them?


Writing, reading, and reflecting are the keys to learning better and faster, not only for the writer, but also for the one doing the reading and the one reflecting on all which has come before them. It's the key to accelerating all of us, and minimizing the gains to the gigantic pile of mistakes.

And that's why geeks should write.