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.