Sunday, March 29, 2015

Impressions of Week 8

    In this week, we had some very exciting things going on, such as the heart-pounding race to finish assignment 2 before 10:00 pm on Thursday and an unguided session of wracking our brains over lab #7. While it does feel nice to not go to labs, it's starting to take its toll. This class is starting to feel more and more like my high school programming class which went something like this: "Here's your assignment, now go teach yourself how to code!" Not that I had a problem with this in high school, but perhaps CSC148 material isn't that easy to figure out on your own. 

    Assignment 2 was pretty straightforward in terms of making the Tippy game, and so far it's the closest we've come to actually making graphics for a game, if you can call the grid made out of text 'graphics.' My grids looked something like this:

  0  1  2  3  
0 /  /  /  /  
1 /  /  x  /  
2 o  o  o  /  
3 /  /  /  x  


    I'd say my greatest accomplishment was to add numbers to indicate columns and rows, so the player doesn't have to count for himself like some sort of peasant. 

    As for the Minimax strategy, I'm pretty sure it works but I don't remember how I completed it or how it works, that memory is suppressed until I'll probably need it in assignment 3. 

Mandatory Acknowledgement of Other Slogs

http://initializationcomplete.blogspot.ca/
When I first looked at this SLOG, I was blown away. The style of writing, the comprehensive understanding this student displays of CSC148 content, it's almost perfect! The only possible flaw I could find here is that there isn't a single post, but surely that's only a small imperfection. 

http://thecstists.blogspot.ca/
One of the great things about this SLOG is that this student actually talked about linked lists, unlike me, because I only talked about A2 in my week 8 post. Even better is that this student actually walks us through their learning process, starting with a concept they had difficulty understanding, and outlining how they figured out the problem. For example, they talked about how they couldn't quite comprehend how the 'append' method is implemented in a linked list, and goes through the steps of how they finally understood it.

Sunday, March 15, 2015

Impressions of Week 7 + Other SLOGS

    In week 7, we learned about Binary Trees, and Binary Search Trees. This is actually a simple concept in itself. There is a node with data, and it references up to two other nodes: left and right. These referenced nodes could also contain left and right nodes, and those could also contain left and right nodes, and so on. Here is a representation of a binary tree, which as you can see starts with a root, and then branches out into left and right nodes.


    This tree is labeled 'Full Binary Tree' because each node actually references two other nodes, except for the leaves (nodes at the very end). A tree like this could also be a binary search tree, which would have to satisfy the following properties: the data contained in each node must be comparable (like integers), the data in the left node must be less than that of its root, and the data in the right node must be greater than its root. Now, the reason this is called a binary SEARCH tree is because this data structure can be searched more efficiently than a list. If you want to find all the numbers within a certain range on a binary search tree, you don't have to visit every node because a search algorithm would know not to visit nodes that will not contain the data its looking for.

And now for the mandatory acknowledgement of other SLOGS:

http://cslogcs148.blogspot.ca/
First off, this URL is very unimaginative. I can already tell just from the URL that this is going to be very dull yet informative...

...well it is informative, I'll give it that. However, this one part bothered me: "The computer is way smarter than a1 now, you can hardly beat it :D" (in reference to the minimax strategy we implemented in a2). What kind of n00b loses to a bot? You gotta step up your game.

http://joshpinkney-csc148.blogspot.ca/
Still a boring URL, but at least it's personalized with the author's name. I particularly like the examples he uses when talking about class inheritance:

>>> horse = horse("Jim", "Black")
>>> horse.noise()
"NEEEEIIIIIIGGGGHHHHHH"

>>> cow = cow("Bob", "White with Black spots")
>>> cow.noise()
"MOOOOOOOOOOOOOOOOOOOOO"

>>> piggy = pig("Timothy", "Pink")
>>> piggy.noise()
"OINK OINK"

I think that this might be the most useful program I have ever encountered, because I always seem to forget what noise a horse makes.


Saturday, February 28, 2015

Monday, February 23, 2015

Object Oriented Programming Concept Summary

So far, we have learned how to create classes, subclasses, methods, and how to implement these in the proper style for both readability and efficiency. But how does this relate to object oriented programming? While we're at it, what is object oriented programming? Well to answer that, we must first define what we mean by an 'object' in the context of computer programming.

An object is essentially a chunk of data; ones and zeros grouped together, represented in a way that humans can understand. For example, a variable in python: NUMBER = 2. As we can see, the variable refers to the integer 2. It also refers to a memory address in the computer, since the variable and the value it represents must be kept track of. It gets much more complicated than just simple variables, as complex classes containing multitudes of data types and information, which are all represented as a single object. At its lowest level, it is just a series of incomprehensible data, but object oriented programming groups it into something that humans can understand, and from there data can be manipulated.

Speaking of manipulating data, this is what functions are for. They might not necessarily manipulate data, but they perform an action with the data. It could represent the data in a certain way, or it could write the data to a file. An object class is a group of functions called methods. The class can be used as an object, and the methods within the class determine how it stores and manipulates data. Typically, there is an __init__ method, which is short for 'initialize,' as that is exactly what the method does. It performs certain actions that allow the object to work. Usually included are a __str__ method (returns a string representation of the object, meant to be readable by the user) and a __repr__ method (a representation that is unambiguous, a raw representation of the data for the use of the programmer). Finally, there might be an __eq__ method, which just compares two objects of the same type. Not all of these methods are implemented in every class. Sometimes it wouldn't be applicable to give a string representation of an object, or perhaps the method is implemented in a subclass.

A subclass is a class that inherits its base features from another class. For example, one would make a generic class to keep track of names, and implement a subclass for the names organized by first name, and one for the names organized by last name. Having generic classes makes the code easier to read, and allows the code to be reused in the future if more subclasses are to be implemented.

Through the use of class objects, very complex programs can be constructed, from video games to integral calculators. Or a video game where the user solves integrals, or an AI that uses integrals to beat video games, or a program that calculates the... okay that's enough, I hope you've enjoyed this summary of object oriented programming in python.

Sunday, February 8, 2015

Week 4: Recursion

    Ah yes, recursion, an absolutely fascinating tool that is used in programming for the sole purpose of drawing trees. So what is recursion? Let me just look that up...


Wait, I swear I spelled that correctly. Why would Google say "Did you mean: recursion?" Oh I get it. Real funny Google, but there goes 20 minutes of my life trying to figure out what was wrong.

    As Wikipedia has said, recursion in computer science is a method where the solution to a problem depends on solutions to smaller instances of the same problem. In CSC148 we would be given a recursive function, which generally involves using the function itself within the function definition to produce a result. We would be given a function, an input, and be asked to trace the result. As expected, there were function calls within function calls within function calls within function calls... And it really hurt my brain. Luckily, the whole point of computers is to compute things that we don't have to, so I can just let my computer's processor take the brunt of the calculations. 

First Impressions: Week 1 - 3

    One of the most important things I took away from the first few weeks of CSC148 was how to actually create programs. In CSC108, our assignments always involved creating functions, which were then used by the provided code. The functions had to do exactly what the assignment described, so the whole process did not feel very creative, and in general it just felt like solving math problems. Even in high school programming we got to make games right off the bat, and as a result I have a whole bunch of files that I can run and start playing. CSC108 has left me with some essentially useless programs. They are useless because they are not implemented into anything, for example, what's the point of a tweet analyzer if it doesn't include a way to extract the tweets from the web? Of course while they are just exercises rather than anything useful in themselves, it sure would make it more fun if we end up with something that can be used.
  
    But now we get to the fun stuff, starting with Assignment 1. We've learned how to make classes interact and build off each other and we know how to write the necessary functions, so now we've used that to create something useful, a video game. Subtract Square is a riveting single player experience where the player must use his mathematical capabilities to... Okay it's not that fun, but it's something. It's a program that I can open, and immediately be playing a game. This is what computer science is about, making programs, programs that do stuff. And maybe my computer player for Assignment 1 will start to learn, and achieve consciousness, and do my assignments for me. Or start the robot apocalypse. I'll be proud of it either way.

Saturday, January 17, 2015

Why Geeks Need to Know How to Write

    When faced with a programming assignment, I find it very difficult to resist the urge to just start coding without a plan. I get a very poorly formed idea of how to solve the problem, and I just start typing away using variable names that make no sense, and zero written explanations as to what the code even does. What I end up with is a jumbled mess of seemingly unrelated text filled with variables called 'a' or 'variable1' and a whole bunch of if statements that reference said variables. Unfortunately for me, the code usually works, and I learn nothing from my mistakes as I'm not the one who has to go back and try to interpret what the code is supposed to do.

    The problem is, if these methods were applied to a very complex program, or if anyone ever had to look through the code to identify a problem, it would probably be just as efficient to look through machine code. While the organization and comments on code do not matter very much to the superior processing power of the computer executing the commands, it is vital for code to be understood by our fellow meat-bags.


    It is one thing for code to work, but if no one can understand why it works in a reasonable amount of time, the code becomes useless if it doesn't work, or needs to be updated. This becomes especially important when working with other people, which often needs to be done in the programming world. Keeping logs of the coding process, explaining what the code does and how it works, and using relevant variable names are all vital if anyone is going to understand your work. If no one understands each other's code, then working together will be impossible, and any program that is too complex will simply not be possible. So for the sake of humanity, write code that is coherent to people as well as computers, or the computers will win.