Saturday 1 March 2014

SLOG #5

Week 7: Recursions, Recursions, Recursions 

After all the labs, lectures, and assignment, I've realized how powerful and efficient recursion really is. It turns what could be tons of redundant lines into less simple and make it easy to understand code. Basically recursion is calling itself again and again until the condition is satisfied. I find that it is very useful when dealing with something that you have to do over and over again but will be very difficult or complicated with iteration loops such as for loops and while loops. Recursion makes it much more simpler than using iteration loops in python. Recursion is useful when dealing with a problem that has a sub-problem which is basically the same problem. Therefore if you didn't write recursion you'd have to write a lot of code that basically does the same thing over and over which could get complicated and easily make you do mistakes. Many examples that were provided to us included linked lists or nested lists that dealt with this problem with a sub problem. Since recursion is basically calling itself almost infinitely, a base case is required where when the conditions(case) is met the recursive call is stopped.

The concept seems very simple and isn't really hard to understand. I mean, you just call the function again and again, right? How hard could that be? Well, I actually found myself struggling at first trying to implement recursive codes. So what I've done was trace recursive codes and figure out the outputs on paper. I really thought that this helped a lot in terms of understanding recursion and ways to implement. We also had a lab where we had to trace recursive functions which I thought was really helpful and helped me solidify my understanding of recursion and implementing recursive functions.

Also, list comprehension which was introduced in the first few weeks of classes came handy in recursion. I found list comprehensions to be a bit difficult to understand at first because it was a very new concept to me and wasn't thought in CSC108, especially when if else statements were thrown in inside the list comprehension then you have to do it recursively which made it even more confusing. At first, what I did in order to understand recursion using list comprehension was actually rewrite the list comprehension into the "long, lengthy way" of making lists and then applying recursion from there and then rewrite back into a list comprehension. After some practice, it helped me to understand recursion with list comprehension much better.

I guess the main point of using recursion is to reduce redundancy in codes when solving problems especially with tree data structures and nested lists or other recursive data structures.


SLOG #4

Week 6: Trees 

In this week's lecture, we learned a new abstract data type, trees. It wasn't very easy to understand at the beginning. I had to try and play around with the example codes provided in order to try to understand trees.

The lab this week went pretty smooth, my partner and I finished half an hour early. We did some unit testing, raised exceptions and some python idioms. 

Sunday 9 February 2014

SLOG #3

Week 5: More Recursions 

In this week's lecture, we dealt with more recursions, tracing recursive functions in particular and recursion relating to the assignment. We also dealt with namespace, making variables global, local or nonlocal, this concept isn't as new to me because I've been somewhat introduced to it in high school although in Java so it's a bit different in implementation but I understood the concept. 

I feel like the labs really help a lot in terms of solidifying the concepts learned in class. It somewhat forces you to understand everything in order to complete the lab. The first half of the lab went smoothly, it was mainly tracing recursive functions which I found easy enough with simple functions like the ones presented in the lab. But the second half was the hard part, it was implementing your own recursive methods for the presented problems.

Sunday 2 February 2014

SLOG #2

Week 4: Recursions 

For this week's lecture, we mainly dealt with recursions, functional programming and unit testing . I found making nameless functions with lambda very efficient as it saves name for other functions if you're only using that nameless function once and it can also be done in one line which I found pretty neat, like the one line structure for making a list from the previous weeks. We also dealt with some unit testing which I found pretty easy as we've done it in this week's lab and a little in CSC108 last semester so that wasn't very hard to understand.

Now the hard part was the recursion, we were presented with more complex recursion examples in class such as the Sierpinski Triangle. This wasn't very easy to understand at first glance, so what I did was understand and trace the recursion example codes posted online and played with them for a bit. I would also try to make my own simple recursive programs in the next few days to solidify my understanding and maybe trace more recursive programs!

On this week's lab we were mainly working with inheritance and unit testing. The lab went pretty smooth, we finished most of the tasks except fixing the code to make it more efficient (reducing the redundant lines) as we ran out of time. Although I did finish it at home and found it to be very simple as you simply need to call the __init__ method from the parent class. Implementing the unittest wasn't very difficult although it required a bit of research mainly for testing the exception.

Sunday 19 January 2014

SLOG #1

Week 3: Object-Oriented Programming

Object-Oriented Programming (OOP) make codes easier to understand because of its structure and it is also very easy to expand your code and make it efficient because of how classes work, with inheritance (subclasses) the code can easily be further evolved and be efficient at the same because it can use methods from the parent class or expand them. CSC108 from last semester somewhat introduced the concept of Object-Oriented Programming because we were taught the basic concepts of making our own classes in python. I feel like CSC148 went more in depth about the properties of a class and fully understanding a class rather than just knowing how to make a new class. The concept wasn't very hard to grasp as I have little previous experience in Java and CSC108 did introduce me to the basic concepts. The lab#2 was also very helpful in further solidifying my understanding of classes and OOP because we had to write a class and compare it to a similar existing one (Stack and Queue). 

The syntax of the parameters (type contract) confused me a bit in the beginning because were taught a different way in CSC108. I feel like the PEP3107 syntax for the parameters is better because it actually type checks the method unlike in CSC108 where you just put it in the docstring. I don't really understand why CSC108 was taught a different way for writing the type contracts. Also there's another way of writing a list in a loop which wasn't taught in CSC108 which was [function(x) for x in list] which I found very cool because it looked very neat and organized as it's only in one line. The two new ways/syntax of writing code was hard to adjust to at first especially when reading a code. I tried writing my own simple codes to familiarize myself with the syntax and as I wrote more and more codes/methods I was able to adapt to it.

Overall, most of the material in the first three weeks were very straightforward and wasn't difficult to understand with the exception of maybe recursions and exceptions. The concepts are somewhat tricky or difficult to understand at first but I may just need to write some examples or do problems involving them to fully understand them.