2013年10月27日星期日
More about recursion and tree traversal
The idea of recursion still somehow confuses me many of the times, I get the idea that recursion is like looping on itself but when it comes down to the thinking of base case, it still gives me a hard time. However, Recursion is really convenient that it allows me to write a relatively short code body and it is really smart. List comprehension is another hardship for me, as the ordering of the "for", "if", "else" placements are somehow confusing, different ordering of them gives different operation. They are somehow that are worth a lot of caution. It is also something smart as it provides a shorter code body as well. I've been stuck on the tree traversal for a short while, I didn't understand the last exercise's task. I ended up spending a couple hours going through lecture notes and some additional tree traversal notes. I figured out the use of preorder and inorder list thus causing everything to make sense. Tree traversal gives me a general idea that when executing a body, we want to use the shortest process and quickest time.
2013年10月9日星期三
Opinions about Object-Oriented Programming and Recursion
Object-Oriented Programming is also known as the OOP, it is quite different than the traditional procedural programming that it focus mainly on creating class and each class is combined of data and our defined functions. It allows us by adding attributes and methods of our own interests and can directly call on that object and only be accessed by that object class. There are slightly more works than just defining functions, however it truly keeps the solution neat and clean.
Recursion, "defining something in terms of itself" according to what the online book How To Think Like A Computer Scientist: Learning With Python 3 states. To me, recursion works a little big similar to inheritance, that many things can be created through itself, to be a little bit more clear that is it bares similar process as for loop but usually recursion has a smaller scale. Also, without going through hassle, recursion allows a function to call on itself when a subproblem is encounter thus solving the subproblem. It is convenient and sometimes time efficient, as recursion gives the same answer but in a shorter expression.
Recursion, "defining something in terms of itself" according to what the online book How To Think Like A Computer Scientist: Learning With Python 3 states. To me, recursion works a little big similar to inheritance, that many things can be created through itself, to be a little bit more clear that is it bares similar process as for loop but usually recursion has a smaller scale. Also, without going through hassle, recursion allows a function to call on itself when a subproblem is encounter thus solving the subproblem. It is convenient and sometimes time efficient, as recursion gives the same answer but in a shorter expression.
Upcoming challenge
It's been quite a while since school started and I am starting to feel a bit more confident on what I am doing now. The exercise 3 allows me to have a more detail idea of how inheritance works, however, somethings I still have trouble defending which class inherit from which, like which is the parent class. I think the opposite way at the beginning, I thought the class with more attributes should inherit from the class with less attributes which is incorrect. I am stuck for quite a while on the Rectangle class that should be inherited from the Parallelogram class in exercise 3. The reason for that is that I don't know how can i modify the the attributes of Rectangle with the class being inherited from Parallelogram, because Rectangle has one less attribute than Parallelogram, that is the theta of the Rectangle is not given to us. However, as I clearly think it all over again, I remember the characteristics of Rectangle that is it is necessary for a Rectangle to have a 90 degree angle thus I set the Rectangle's attribute in its initializer method with a default mode of (self, base, side, 90) which actually give me the correct output of what I want. Being able to identify the key here in the Rectangle class allows me to solve the mystery of the Square class inheritance problem as well. A1 is an even more challenging task for us, but thanks to our professor that he allows us to work with partners. This is surely something that can benefit us, not by lessening our workload, but allow peers to help each other and solve problem together. However, to me, A1 seems a little bit too hard for students because the logic thinking involved is completed and the tkinter documentation is somewhat confusing. The test upcoming next week will be a real challenge to me and really hope I can manage to do okay on this test and goes on with this course.
2013年10月1日星期二
Followup on programing style
In this week’s lecture, we went through some class examples and
learned about how to raise exception case. I found raising exception
amazing and came to an understanding of how python raise thoseValueError
or NameError etc.I spent a couple hours working on my exercise2,
but when I finally completed it and submitted it to MarkUs,
something interesting happened.
Most of the testcases had passed except
for the testcase called “Test for PEP8 compliancI spent some time on trying
to figure out what is PEP8 and realized that PEP8 actually refers to a style checker, thus I know that the style of the way we program matters as well. This
implemented me a new mindset, as I previously thought that only the concept matters and the structure of the algorithm do not.
Now, I am trying to reinforce the idea of programming style so I can be on the right track and hopefully I can get used to it as soon as possible.
learned about how to raise exception case. I found raising exception
amazing and came to an understanding of how python raise thoseValueError
or NameError etc.I spent a couple hours working on my exercise2,
but when I finally completed it and submitted it to MarkUs,
something interesting happened.
Most of the testcases had passed except
for the testcase called “Test for PEP8 compliancI spent some time on trying
to figure out what is PEP8 and realized that PEP8 actually refers to a style checker, thus I know that the style of the way we program matters as well. This
implemented me a new mindset, as I previously thought that only the concept matters and the structure of the algorithm do not.
Now, I am trying to reinforce the idea of programming style so I can be on the right track and hopefully I can get used to it as soon as possible.
订阅:
博文 (Atom)