Object-oriented programming, as its name suggests, deals with objects that contain data, and code, which is implemented as methods. In this course, we dealt with classes and inheritance.
A class is an object that contains code in the form of methods, that can be implemented for any instance of the class. An example of a class and its methods is a class for a day planner. Every instance of the class is a day, and the class might contain methods that add an event, remove an event, and one that checks to see if any events overlap, in addition to an initializer method which creates instances of the class. These methods execute properly for any instance of the class (which is a day) and this class structure is much more efficient than writing separate functions that are not connected as it often requires less code and is more ordered.
Some problems, however, require more complex solutions that just one class. In the case where instances of a class share methods, but not the implementation of those methods, inheritance may be used. A simple example of inheritance that deals with shapes was shown in lecture. The shape class has a method that initializes a shape, one that stores the starting coordinates of the shape, one that calculates the perimeter, and one that calculates the area. While all shapes share these properties, only the method that stores the starting coordinates of the shape will execute properly regardless of the type of shape created. Both the perimeter and area methods are specific to the type of shape created. In this case, subclasses for each shape are created and inherit shared methods from the general shape superclass. The intializer and coordinate methods would be implemented in the superclass because they are shared with all shapes, while the perimeter and area methods would be left unimplemented in the superclass and would raise an error if called saying that a subclass is needed. In the subclasses, the coordinate method would not need to be implemented because it is inherited from the superclass, but the area and perimeter methods can be implemented differently in each shape's subclass. This process is much more efficient than creating separate classes for each shape, especially in larger cases, because it prevents duplication of shared code (the coordinate method would have to be duplicated in every separate class without inheritance) and is more organized.
This course also introduced three new abstract data types so far: stacks, queues, and trees.
Stacks are a last-in-first-out data type that can be envisioned as a stack of paper on a desk. Items can be added on top of the stack, but only the top item can be removed first, or the stack of paper will collapse. Generally, stacks have three key methods aside from the initializer: a method to check if the stack is empty, a method to add an item on top of the stack, and a method to remove and return the top item on the stack.
Queues are similar to stacks except they are a first-in-first-out data type, similar to a line at a cashier. They contain the same key methods as stacks, except the implementation is slightly different.
Trees are a recursive data type, meaning each tree is made up of smaller subtrees. An example of a tree can be created by flipping a coin and recording the possible results. After one flip, the possibilities are only heads and tails, after flipping the coin again, each possibility from before now also has two possibilities. Due to the recursive nature of trees, many of the methods implemented in a tree class also require recursion, such as determining the end values of the tree (the leaves) the number of intermediate values (nodes), or the maximum height of the tree.
Sunday, 22 February 2015
Sunday, 8 February 2015
Tracing Recursion
When recursion was first introduced in lecture, I was a bit confused about the syntax of tracing it, even though I understood the concept. The handout that we completed together in lecture was very helpful as it gave me concrete examples to work from when tracing other recursive functions. As well, the lab exercise that actually required us to write a recursive function was extremely useful as it gave a further understanding as to how recursive code works. After the lab exercise and quiz, I felt comfortable with tracing recursion and had no problems completing the test question that dealt with this topic.
Friday, 30 January 2015
The First 3 Weeks
In the first three weeks, we mainly covered classes and inheritance. Most of the material covered before inheritance was review from CSC 108, with the exception of the __repr__ method and list comprehensions. For the most part, I had no trouble understanding inheritance as I enjoy coding with classes.
During the second week, the first assignment was posted. At first, my group members and I were confused by the wording of the assignment, but after re-reading it a few times and working on some of the code, we understood it better. By the end of week three we had nearly finished the assignment and we just needed to add a few aesthetic details, docstrings and special methods.
So far, I am enjoying the course, and it helps to have the same professor who taught my CSC 165 section because the consistency in teaching style makes it easier for me to absorb what he is teaching.
During the second week, the first assignment was posted. At first, my group members and I were confused by the wording of the assignment, but after re-reading it a few times and working on some of the code, we understood it better. By the end of week three we had nearly finished the assignment and we just needed to add a few aesthetic details, docstrings and special methods.
So far, I am enjoying the course, and it helps to have the same professor who taught my CSC 165 section because the consistency in teaching style makes it easier for me to absorb what he is teaching.
Sunday, 25 January 2015
Why do Geeks need to know how to Write?
A Geek, by definition is "an enthusiast or expert especially in a technological field or activity". Thus, geeks know more than the average person about their area of expertise. In order to communicate and share their ideas and knowledge they need to be able to write effectively. This means being able to communicate with different audiences, from other experts to people who have no knowledge of their field.
Keeping good notes as a geek is working on a project allows them and others to look back on what they've done and understand their process and reasoning. An example is commenting code. If a programmer writes succinct and accurate comments, another programmer reading their code will be able to easily comprehend their process instead of having to look through the code line by line to understand what is happening. This is especially beneficial when reviewing large coding projects as it can be very time consuming to study every line of code.
A geek may have to write for a variety of audiences. When writing for other experts, such as in a technical journal, they need to be able to convey their findings clearly so that others in their field can evaluate the merit of their results. The use of technical terms is appropriate for this audience. However, when writing user manuals, the use of technical terms would be ineffective and confuse people who are not familiar with them. In this case, concepts need to be expressed in a way that is understandable to the average user. As well, a geek may be required to write a business proposal, whether seeking funding, or trying to market their product. Therefore, the ability to write persuasively is an asset. This is also true when preparing and delivering presentations as good notes that are engaging and informative will keep the audience's interest.
The term geek is synonymous with someone who is not able to communicate very well, however, the opposite is essential to be a successful geek.
Keeping good notes as a geek is working on a project allows them and others to look back on what they've done and understand their process and reasoning. An example is commenting code. If a programmer writes succinct and accurate comments, another programmer reading their code will be able to easily comprehend their process instead of having to look through the code line by line to understand what is happening. This is especially beneficial when reviewing large coding projects as it can be very time consuming to study every line of code.
A geek may have to write for a variety of audiences. When writing for other experts, such as in a technical journal, they need to be able to convey their findings clearly so that others in their field can evaluate the merit of their results. The use of technical terms is appropriate for this audience. However, when writing user manuals, the use of technical terms would be ineffective and confuse people who are not familiar with them. In this case, concepts need to be expressed in a way that is understandable to the average user. As well, a geek may be required to write a business proposal, whether seeking funding, or trying to market their product. Therefore, the ability to write persuasively is an asset. This is also true when preparing and delivering presentations as good notes that are engaging and informative will keep the audience's interest.
The term geek is synonymous with someone who is not able to communicate very well, however, the opposite is essential to be a successful geek.
Subscribe to:
Posts (Atom)