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.