Sunday, 5 April 2015

Week 12 - Final Impressions

    CSC148 has been my favourite course this term, so I'm sad that it has come to an end. Although I initially found the course to be much more difficult than CSC108, I can proudly say I overcame all of my difficulties.

    There were many challenging concepts taught in this course, mainly recursion and trees. Recursion seemed fairly straightforward until trees were introduced. Trees were so confusing to me for many weeks. I had no idea how to traverse a tree for quite a while. Needless to say, I couldn't collect a node's data during a tree traversal since I couldn't even traverse a tree. Going to the CSC Help Centre the week before the strike happened was one of the best decisions I made for myself. The TA I talked to was so helpful and after talking to him I could finally traverse trees. However, I had a bad habit of only being able to use list comprehensions to do recursion with trees. Thankfully, I broke out of this habit for assignment three as I learned how to unpack a list comprehension into a few lines of code. This also allowed me to use a different data type from a list which was helpful for assignment three since sets were required. Although I found it annoying that sets had to be used, this requirement is what led me to be able to write recursive functions that weren't reliant on a list comprehension.

    Overall, this course was extremely fascinating as were the professors. Looking back now, I don't think CSC148 is too difficult of a course at all as long as you keep up with the lectures and lab exercises. But most importantly, get help when you need it!

Sunday, 29 March 2015

Revisiting My Early Impressions of CSC148

    This week's assigned topic is to revisit an earlier SLOG post. I'll be revisiting my second post. In this post I discussed my problems with writing functions. In February, I frequently wrote my function body before the docstring, which went against the function design recipe. However, I have improved from then since I now can picture what a docstring might look like before I write the body.

    I also mentioned how I found recursion to be a difficult concept. While this is still true now, I have a much better understanding of recursion after lots of practise with writing recursive functions. For example, I was often lost with how to write the body during many of the labs and I couldn't understand what to do until I saw the lab solutions. But today I was able to write the function grow for assignment three, although it took a few hours. My hope is to master this concept before the final exam.

    Looking at this slogger's post, I know I'm not the only one who still has some trouble with recursion. I found it difficult, as did this slogger, to use recursion together with trees. For a long time I didn't know how to traverse through a tree using recursion and I also found it very difficult to recursively build a tree for assignment three. The examples in lecture made sense, but I wasn't keeping up with the lab exercises during the strike so I fell behind on the course work. Of course I only have myself to blame, for not keeping up with the work, but I have caught up on all the material as of now.

Sunday, 22 March 2015

Impressions of Week 9

    In this week's lecture, we reviewed the insert and delete functions for a binary search tree. Neither of these functions were new as they had been in our previous lab exercises but I appreciated the review since there was also a test this week.

    I found the first question for this term test to be the most difficult. It was obvious to me that I had a poor understanding of how nodes formed a tree as I was very unsure of what the maximum and minimum height of a tree could be given a certain number of nodes. So I will make sure to review trees properly so that I don't make the same mistakes again on the exam. However, the other two questions seemed fairly straightforward. Although I am worried I might have made a few careless mistakes, this test was fair. Like this slogger, I made sure to take advantage of my aid sheet for this test unlike the first test and it was extremely helpful. Even though I hardly looked at my aid sheet, since I knew and understood what was written on it, the process of creating it was a good study habit. I am considering making aid sheets for my other courses as another way to hammer important information into my brain.

Sunday, 15 March 2015

Impressions of Week 8

    This week we learned about linked lists. I found linked lists to be an easier concept to learn than trees since the structure is somewhat linear as each node in a linked list has a reference to the next node unlike in trees where each node might have a left or right child. This week's lab exercise was easier to me than week seven's most likely because I am more comfortable with linked lists than I am with trees.

    However, I am not entirely comfortable with the first approach for linked lists via lists made up of an item/value and a sublist. It doesn't as intuitive to me as the node class and wrapper class for a list approach to creating a linked list. I will have to go through the lecture slides again to understand this approach better.

Sunday, 8 March 2015

More Impressions of Week 7

    This week we learned about binary search trees which are different from regular trees. In a binary search tree the data is comparable and the data in the left subtree are less than node.data while the data in the right subtree are more than node.data. This makes a tree easier to traverse since it is sorted in a sense. For example, if you were looking for a node with a certain value you would know how to look for it from the root since the left subtree contains data that is lesser and the right subtree contains data that is greater. Hence you wouldn't waste time looking at all children in the tree.

    We also learned about three different tree traversals called inorder, preorder, and postorder. These traversals done by recursive functions and the nodes in a tree are visited as follows in the image below:

1 represents the first node that is visited, 2 the second, and 3 the third.

    As I mentioned last week, I found week seven's lab exercise to be much more difficult than previous labs. I am pleased to know that a fellow slogger also had difficulties with list_between and list_internal_between like I did and was able to solve his/her problem. I had the same issue of trying the write one line of code in my else block to make the two functions work. Fortunately, by seeing a TA at the CSC Help Centre, I realized that not all functions can work with just one line of code in an else block. By writing a few more lines of code I was able to make both of those functions work.

Sunday, 1 March 2015

Week 7

Note: I would like my TA to mark my post about object-oriented programming.

    This week's lab was more challenging to me compared to labs from previous weeks. I thought I had understood trees well enough, but I struggled to get list_between and list_internal_between working until just before the quiz began. I didn't feel that I did well on the quiz either, so I went to the CSC Help Centre, for the first time, later that day. The TA who led the help session was extremely helpful to me and I understand how to recursively call a function involving trees much better now.

Sunday, 22 February 2015

Reflecting on Term Test 1

    I think it's funny that I talked about NotImplementedErrors and method overriding in my previous post, and that they are what caused me to lose a lot of marks on the first term test. I completely forgot that NotImplementedErrors should be in the parent class and I instead wrote code that was specific to a subclass in the parent class. This was a major mistake and it caused me to do much more badly on the test than I would have had I used NotImplementedErrors and overridden the methods in the UndergraduateStudent subclass. But it's a lesson well learned.

Sunday, 15 February 2015

Object-Oriented Programming

    Object-Oriented Programming (OOP) is a style of programming based on objects. This might lead you to ask "what are objects?" and that's a good question! An object could be a variable, a data structure such as a list, or even a function.

    You might be thinking that sounds fine and dandy, but there's no reason for you to bother with OOP because your coding style right now works great. I'm going to attempt to change your mind by telling you about an example I learned in class.

    Let's say you wanted to create a program that worked with different shapes, such as circles, squares, and triangles. These are all different shapes, but they have similar properties because they are shapes. For examples, these shapes would all have a position (x, y). To move a shape, you'll make a function to move the shape. We'll call this function move_to, which will move the shape to a new position (x, y). It happens to be the case that all shapes can be moved with this function. Thus it makes sense to group these shapes by creating a class, called Shape, so that each Shape created as a subclass (e.g. Circle, Square, Triangle) will have access to the function move_to which has become a method in the class Shape. Isn't it amazing how this prevented you from rewriting the same code?

    But you might say that you will have a problem now because these shapes can't use the same formula to calculate area, and that's right. What we can do is create a method in Shape called get_area and put the following in the method's body: raise NotImplementedError('Need a subclass')

"Well that seems stupid", is what I initially thought when I first heard of a NotImplementedError in class. I learned minutes later that it is actually extremely useful. We put a NotImplementedError here because there is no one way to calculate the area of all Shapes. So this error tells the client that there is a subclass (e.g. Circle) that knows how to calculate the area. In a subclass such as Square, we would create a method named get_area that calculates the area of a Square. "But how can you do that when you already have a get_area method in Shape?" is something you might be wondering. By rewriting the method get_area in Square, we have overridden the get_area method in Shape. When Square is asked to calculate its area, the get_area method in Square will be called instead of the get_area in Shape. This is because the method is looked for locally first before it is searched for in the parent class.

As you can see, with OOP you can use inheritance to create classes with similar properties to a parent class and you can override methods from the parent class to something different in a subclass. It might be more work than what you're used to, but the end result is definitely worth it as it will save you time and make your code less redundant and more structured.

Sunday, 8 February 2015

Thoughts on Recursion

    During week four of csc148, we learned about recursion. The idea that a function could call itself over and over again was mind boggling to me, not to mention very confusing. Thankfully, the recursion tracing exercises from lecture and the lab were extremely useful to me and I can now say that I find recursion a little less confusing.


    However, I still find it difficult to create my own recursive methods. I hope that with more practice I will get better at implementing recursive methods since I recognize that recursion is a powerful tool.

Sunday, 1 February 2015

Impressions of CSC148

    The increase in difficulty from csc108 and csc148 has made me realize how important partnership is for this course. When I first read the assignment one sheet, I was very confused and didn't know how to start the assignment. Although highlighting the nouns, verbs, and adjectives for each of the classes helped, it was talking about about the assignment with my partner that really helped me figure out how to tackle the assignment. Discussing it out loud with someone else allowed me to critically analyze what needed to be done.

    I've also noticed that I have a really bad habit when it comes to writing docstrings. I always leave them blank until after I've written code for the body of the function. For some reason, I'm unable to figure out what an example call for the function should look like until the body is complete. I am hoping to fix this habit in the future since I know this course is only going to become more difficult now that we have been introduced to recursion, which I find so confusing.

   

Sunday, 25 January 2015

Week 3: Why Geeks Should Write

    Rather than asking why geeks should write, we should be questioning why anyone ought to write.

    Whether you believe it or not, writing helps you become a better thinker. The process of writing requires you to think about what you are writing and ensure that it's comprehensible to its intended audience. Thus, you'll have a deeper understanding of your thoughts as you write them out. By writing, you'll constantly ask yourself the following questions:

  • Who is my intended audience?
  • What do I hope to accomplish by writing about this topic?
  • Will my writing make sense to readers?
  • Can I make my writing more straightforward and concise?
    Now you might be thinking that while writing is useful to some, it doesn't apply to computer scientists. This is not true at all! For example, when you write code you will also be writing comments to help other programmers understand your code. Your comments and names for your classes, methods, and variables should be meaningful so that your code can be easily understood. Hence the questions above can also be applied to code. In addition, proofreading and testing code are quite similar. You wouldn't submit code that you didn't test just like you wouldn't hand in a paper you didn't proofread (at least I hope so for your sake).

   The benefits of writing are great and they will be evident the more you write about anything, code included!