Thursday, 19 February 2015

Object-Oriented Programming

    Object-oriented programming is a programming paradigm based on the concept of "objects", which are data structure that contain data, in the form of fields, often known as attributes; and code, in the form of procedures, often known as methods. It attempts to provide a model for programming based on objects and a distinguishing feature of objects is that an object's procedures can access and often modify the data fields of the object with which they are associated.
    As what we learned in lectures in these few weeks, the class Stack is a good example. In this class, one of the most attractive features is that it is a last-in, first-out stack of items (LIFO). We can regard it as a real book stack from which we can take and put a book on the top of the stack. Obviously the books are just like the objects. In fact, there are methods in it called 'pop', which aims to pop and return the top item in the Stack; 'push', which aims to place the object on the top of the Stack; and 'is_empty', which checks whether the Stack is empty. These three methods enable us to access and modify the data fields of objects.
I'm more than excited to learn more about the object-oriented programming language Python.

Sunday, 8 February 2015

Impression of recursion

    In the last few weeks, we learned about recursion. Actually when I saw this word, things that came to my mind first are 'for loop' and 'while loop'. After the lecture, I found that in fact, it's more concise and, even beautiful!
    Recursion is a method of solving problems that involves breaking a problem down into smaller and smaller subproblems until you get to a small enough problem that it can be solved trivially. Usually recursion involves a function calling itself. While it may not seem like much on the surface, recursion allows us to write elegant solutions to problems that may otherwise be very difficult to program. Instead of writing several lines of 'for loop' and 'while loop', recursion can just solve the problem in much fewer codes, which is absolutely its advantage. However, I also came up with the problem that sometimes it may take more time to work out a recursion than just to use a for loop or while loop. Anyways, it's a great way to solve big problems and I'm sure it'll be useful in our future learning.