Object-oriented programming (OOP) is a model for programming language centered and modeled around objects and data, rather than actions or logic. Traditionally, a program was seen as just a logical procedure that takes an input data, and after processing it, returns an output data. Furthermore, as stated earlier, object-oriented programming is based on objects. Objects are abstract data types. They are structures that contain data, often known as attributes, and code, known as methods. Additionally they have both a state (data) and behavior (code).
In this type of programming (object-oriented), the programs are designed to interact with one another. While, there are diverse ways of object-oriented programming, most languages are class-based. This means that the objects are instances of classes; this determines their type. Python, C#, C++, Java, Perl, and many other computer languages are significant object-oriented languages. In class, we have been learning object-oriented programming and concepts. Object-oriented programming concepts, then are concepts such concepts as learned in class, such as classes, subclasses (and Inheritance), stacks, queues, and trees.
The concept of data class, makes it possible to define subclasses of data objects, that share some of the main class characteristics or attributes. The process of inheritance, which is crucial to programming subclasses, is a more efficient way of coding, since it reduces time spent programming the same functions as well as ensure a more accurate code. Additionally, the concept of classes allows a programmer to create a new data type not already defined in the language itself. This is useful for many reasons. One of the main reasons, classes are useful and make your code more efficient, is that when implementing classes, the programmer has control over the whole class as well as any subclasses.
Additionally, as when used in Assignment 1, classes can be used to make a general class, with more specific subclasses. In this way, a general class for a game state, can have numerous subclasses for specific games, such as tic-tac-toe, subtract square or even connect 4. While the game state for these games are unique and different in many ways, they do share some similar attributes and are the same "type" of game. They are both 2 player, sequential, zero sum games, and having a general game state to reflect this is quite useful. Using object-oriented programming is very useful and has numerous advantages.
Monday, February 16, 2015
Monday, February 9, 2015
Week 4: Tracing Recursion
Last week in class, we learned about recursion. A strange way in which a function can call itself in the function. Recursion is strange in that the function calls itself. This would seem as though the function is incomplete or that an infinite loop would be created. However, recursion works, and in order to understand it, smaller and simple examples must be examined and understood. That is what we did in class. In order for us to understand recursion, we must be able to examine the function and how the function works with simple examples, and then other more complex examples. In this way, recursion can be better understood.
I had trouble understanding recursion, when it was first introduced. However, tracing the examples really helps to explain recursion. Similarly, I had trouble implementing recursion, a trouble I may still be suffering. I understand the concept of recursion quite well, thanks to the examples. However, actually having to implement recursion is something I find difficult. Understanding when exactly I should use recursion and the way in which it should be implemented is something I struggled with that week. There seems to be a sort of "formula" or "form" in writing recursion code, where there is an "if...else" statement. The "else" statement is usually important for (tracing) the simplest recursion call. The "if" statement is harder to write, and where I have the most difficulty. Hopefully, practicing and writing more code should help me overcome this problem. Also, I plan on researching recursion more and looking at recursion code more, in order that I familiarize myself with recursion.
Additionally, in lab, this week I used the python visualizer to trace recursion calls. This helped to solidify how and why recursion works. This also made it easier for me to understand the way the function is implemented. All in all, tracing code to understand the concept and practicing problems to implement it, will give me a better understanding of recursion.
I had trouble understanding recursion, when it was first introduced. However, tracing the examples really helps to explain recursion. Similarly, I had trouble implementing recursion, a trouble I may still be suffering. I understand the concept of recursion quite well, thanks to the examples. However, actually having to implement recursion is something I find difficult. Understanding when exactly I should use recursion and the way in which it should be implemented is something I struggled with that week. There seems to be a sort of "formula" or "form" in writing recursion code, where there is an "if...else" statement. The "else" statement is usually important for (tracing) the simplest recursion call. The "if" statement is harder to write, and where I have the most difficulty. Hopefully, practicing and writing more code should help me overcome this problem. Also, I plan on researching recursion more and looking at recursion code more, in order that I familiarize myself with recursion.
Additionally, in lab, this week I used the python visualizer to trace recursion calls. This helped to solidify how and why recursion works. This also made it easier for me to understand the way the function is implemented. All in all, tracing code to understand the concept and practicing problems to implement it, will give me a better understanding of recursion.
Tuesday, February 3, 2015
Week 1-3: ADTs, Stack, and Subclasses
The first few weeks of CSC148 have come and gone, and already we have covered ADTs, Stacks, and Subclasses. Assignment 1, was due Thursday, January 29 and in it I had to implement the concepts (particularly the concept of Inheritance and Subclasses) learned in class. I learned how to raise an Implementation Error and how to create Stacks. I also learned that about how to create a Subclass and what it means for the subclass to inherit attributes of the class.
It was difficult to implement the concepts learned in class. A stack in particular is something I had trouble understanding at first. However after reviewing the material, I am now confident in the material. One achievement for this week is my completion of the Assignment 1. As mentioned earlier, in Assignment 1 I had to implement the concept of Inheritance and Subclasses. I didn't find that particularly difficult. However reading the objective of the Assignment and figuring a way to complete it was difficult. I found it hard to begin and trouble understanding how the game would play, but after a good night's rest, I realized that the game would play by using the code: "if __name__ == '__main__'. Once I realized this, it was only a matter of coding the actual game.
I understood the way to go about programming the code, however, I did run across a few bugs. I was unable to actually get the game to run smoothly with no errors, probably because of the helper function I created to keep track of the legal moves was not working for all cases. However, despite the setback and failure, I did learn a lot through this assignment. Unlike the previous computer science course I took last year (CSC108), where the professors made the assignments as easy as possible, and told you what functions to complete and how to go about completing them, this was quite harder. The handout did not say what functions to write or how to write the subclasses. It was difficult getting started, especially since it seems like an overwhelming and difficult task. Once I got started, however, it wasn't as hard a task as I expected it to be.
It was difficult to implement the concepts learned in class. A stack in particular is something I had trouble understanding at first. However after reviewing the material, I am now confident in the material. One achievement for this week is my completion of the Assignment 1. As mentioned earlier, in Assignment 1 I had to implement the concept of Inheritance and Subclasses. I didn't find that particularly difficult. However reading the objective of the Assignment and figuring a way to complete it was difficult. I found it hard to begin and trouble understanding how the game would play, but after a good night's rest, I realized that the game would play by using the code: "if __name__ == '__main__'. Once I realized this, it was only a matter of coding the actual game.
I understood the way to go about programming the code, however, I did run across a few bugs. I was unable to actually get the game to run smoothly with no errors, probably because of the helper function I created to keep track of the legal moves was not working for all cases. However, despite the setback and failure, I did learn a lot through this assignment. Unlike the previous computer science course I took last year (CSC108), where the professors made the assignments as easy as possible, and told you what functions to complete and how to go about completing them, this was quite harder. The handout did not say what functions to write or how to write the subclasses. It was difficult getting started, especially since it seems like an overwhelming and difficult task. Once I got started, however, it wasn't as hard a task as I expected it to be.
Subscribe to:
Posts (Atom)