Saturday, 28 March 2015

Revisiting recursion

This SLOG I’m going to revisit my thoughts on recursion. This SLOG might be a bit shorter because I might be rehashing some old ideas.

My previous thoughts on recursion were quite harsh. My main issues with it were that it's difficult to read, it's hard to create a mental image on how it works, and it is proving difficult to debug. I still agree with my main sentiment, recursion should be avoided whenever possible. However I have toned down my stance on the topic.
I originally found recursion difficult to read. I still 100% agree with this. Despite becoming incredibly familiar with recursive code I still find it a huge pain to read. I am definitely not alone with these thoughts, I have talked to classmates, upper years, as well as professional software developers. I found it incredibly interesting when one of the software developers were told me that recursion is usually frowned upon during most projects. When I asked why, he said that when new people are brought onto a team, recursive code can be very difficult for them to understand how the pre-existing code works.
My next point was that recursive code is difficult to visualize. A work around for this is drawing diagrams. While it is hard to visualize, even the most artistically challenged (AKA me) can draw a crude diagram that represents how an algorithm works. So I find this to be significantly less of an issue than I did previously
My last point was that recursive code is difficult to debug. My experience with minimax is first hand evidence with this. The most frustrated I have been all year was having to debug the minimax algorithm. The main difficulty with going through the code was that it hard to see exactly how the code was looping. With iteration it’s very easy to see how the program loops. With iteration it is usually much easier to see where the code is going to end. With recursion it is exceedingly difficult to see what the code is going to return.
Although I do have some apprehensive thoughts about recursion, I can see how it is very useful. As I’ve been working with recursive code more and more throughout the semester I have gotten more comfortable working with it. Recursion in some instances how for easier manipulation of abstract data structures such as binary trees, linked lists, and many others. So while I find it challenging to work with I do accept that it is needed.

Tuesday, 17 March 2015

Trials and Tribulations - Term Test 2

This past week we wrote our second midterm test, I am going to write about my thoughts of the test.

The test was composed of three questions, question one was regarding the possible height of binary trees. Question two was writing a function utilizing binary search trees with integer elements and returning a list of integers that are even and found between a given interval. The third question was to write a function using linked lists to remove the first occurrence of a node and adds it to the node following.

To prepare for this test I completed all the tutorial questions, I reviewed all my notes from class, and I experimented with the code written in class. I felt very comfortable with the concepts of recursion and binary trees. I had very few problems with writing code that traversed the branches and manipulated trees. Every problem I had was fixed with some deep breaths and some thinking.
However I was less comfortable with linked list. I understood how linked lists worked however I kept making mistakes when writing code. I tried to focus much of my studying on reviewing linked lists, however I never really felt comfortable with it.
I breezed through the first question, and quickly moved onto the second. The second question required some thinking and a bit of planning, but with some patience I found what I think is a very effective solution. Finally the third question. My unease with linked lists really effected my mentality with this question. I was really apprehensive with this question. I was unable to create a solution that I was happy with.
In the future I think I will try to prepare better for the final exam. I will try to ask my professor, a TA, my classmates, or even an upper year student for some clarification. Overall I think I did very well on this test, I am just a bit unhappy with how I did on the third question.


Thursday, 12 March 2015

Trials and tribulations - Assignment 2

Last week we finished assignment two, so this week I am going to write about my experience with working on it.

Assignment 2 was split into basically two problems, the game Tippy, and the strategy Minimax. Tippy was not exceedingly difficult. I found it mainly to be time consuming. I found that a little planning before starting allowed me to easily complete this part of the assignment. My main technical challenge with Tippy was figuring out the algorithm and writing code for determining who the winner was. I do not know why I found it difficult, even with drawing diagrams and visually solving it multiple times I couldn’t implement it. After a couple attempts I manage to successfully implement it.

The main technical challenge was implementing Minimax. I found the description given in class and found in the assignment handout to not be sufficient, so I had to do some research to fully understand how minimax works. I found this video,


to be extremely helpful. After watching this it took a little more reading, some discussion with some classmates, and some more views of the video until I fully understood how the algorithm was supposed to work. So now that I know what I’m trying to implement it was time to go into the planning stage. I drew diagrams, wrote some test code, and discussed the problem with a friend. After doing this I felt ready to start coding.
I wrote code which I thought it should in theory work, when I started to run some tests on it, not only did it return the wrong move, it went way too fast. Using some print statements I found that it was not traversing the tree correctly. After fixing this problem I ran it again, now it was running for the correct length of time, however it was still returning the wrong value. At least it was what I thought to be the wrong value. In tippy on a 3-by-3 board the middle position (1,1) in the strongest move. After a lot of time, testing and hair pulling I finally realized that my original algorithm needed some slight tweaking in order for it to work. Finally! I had it working. The elation I felt when all my test cases passed was such a relief!


Sunday, 8 March 2015

Object Orientated Programming (OOP)

I missed class last week due to feeling unwell so I'll discuss my experience with object orientated programming.

I first learned about object orientated programming when I first started to learn programming in high school. It was describe to me as the four pillars of object orientated programming; abstraction, encapsulation, inheritance, and polymorphism. While we haven't yet referred to object orientated programming as with respect to the "four pillars" we have at least briefly talked about them.

We have specifically talked about abstraction (abstract data types) and inheritance (subclass). We have sort of merged inheritance and polymorphism. Polymorphism is when a subclass can share functionality with it's parent class and also define functions of it's own. However but not vice versa. We have already exploited this multiple times without discussing it as it's own characteristic of OOP.

We have only very briefly and simplistically discussed encapsulation. The best way I can think to describe encapsulation is that your putting a "shell" around objects to simplify their uses. This shell separates, or encapsulates, objects, functions, and data from one another. One of the most, if not the most common uses of encapsulation is that of data hiding. Encapsulation does not mean data hiding, but it allows for it.

I think it's very important to talk about the four pillars of object orientated programming. When I was first learning about these "four pillars" I found it very difficult to wrap my head around. But as I gained more experience as a programmer it opened my eyes to how important these characteristics of OOP actually are.