Sunday, 15 February 2015

week #6 --- Summary of Object-Oriented Programming concepts

    Object-Oriented Programming is a programming model that stores different concepts into some data structures called objects and those objects are created within classes containing similar features. Then we can interact and manipulate the different attributes of those objects within the classes, and use the methods of the those objects in the same class.
 
    Inheritance is one big concept in Object-Oriented Programming. It's about how we can implement new classes based on already existing classes and then expand the features in our new classes without having to write everything over. When writing classes with inheritance, it's important that we sort out the order and the organization of the classes first. For instance, there is always one parent class called the super class that contains all the starting features, but may also have some methods that can only be determined in the new classes based on this super class, then in this situation, we may raise a NotImplementedError when such methods are classes. After we've got a parent class, by applying the concept of inheritance, we may write subclasses based on the existing parent class without write everything all over again. Another important factor we should be careful about is that we need to be extra careful when we decide to change something in our parent class. Sometimes, some programmers would share the classes they have written to the internet, and people may write code or even implement new subclasses based on those programmers' classes, but if the programmers change some things in the codes they distribute to the internet, the changes may cause all kinds of error and confusion for other people, as the codes in the classes now are different from the past, so remember, it's all connected!

Saturday, 7 February 2015

Week #5 --- Impressions of tracing recursion from week 4

   Recursion, What is that?! When I first saw the function has the name of the function within the function itself, my immediate first impression was just 'How is it going to work?'. It looked really weird at first sight! Gladly, Professor Danny explained to us step by step what recursion is about and what kind of problems we can use recursion to solve.
    Basically, recursion is an algorithm that you plug in the name of the recursion function into the function itself for certain conditions with some other elements in the function for 'other' conditions, so when an argument is processed, it will either meets the 'other' conditions and be directly executed, or be broken down into pieces, and those pieces will be processed through the same recursive function again until they meet the specific 'other' conditions.
 
    For example; We have a deck of one hundred random poker cards, and we are to find the joker card in the deck. It's really gonna take one person some time to find it, but with recursion, we may break the one deck of one hundred cards into ten decks of ten cards, and have ten people looking for the joker card the same time, which would be a lot more efficient, or we may even break the ten deck of ten cards into one hundred decks of one card and have one hundred people just checking their only one card the same time. In this way, We will be able to find our joker card in a blink of eye! Now, that's the beauty of recursion! It is how we can break down one fairly complex problem into many pieces and solve all those little pieces individually. It can just make our codes a lot more efficient!

    I found the tracing of the recursion in class to be quite helpful. It taught me the idea of how the recursion break down and go recursively, and how is the recursion function working when we do it on a computer. Same thing for the ones in lab, those tracing of different type of recursion functions introduced me to a variety of how we can use recursion to solve different types of problems, so recursion came to me as understandable and it did flow quite well in my mind, but it was no longer the case when I had to write recursive functions myself. For the last question in week 4's lab, I was stuck on it for almost half of the class, and I couldn't really figure it out until the TA gave me some obvious hints. At that time, I realized that my mindset of writing recursion function was wrong. I tended to think about the huge amount of the broken down pieces at the end, and that was just highly inefficient, because I really didn't have to. All I should have done was to think about the base cases when there will be no recursion and the argument will be directly executed, and the recursive cases when the function needs to break down the argument into many more pieces, then carry on to how I can develop the detail of the function based on what the function's about.

    Now I feel that I'm much more adapted to the writing of recursive functions, and I'm really looking forward to how I can make use of recursion in the future.



Here is another explanation of recursion from another slogger