Monday, 23 March 2015

Impressions of Week 8

I admit, when we were first introduce to linked lists, I wondered what the point of them was. The concept -  a collection of nodes, each with a value and leading to another node except for the end node - seemed too simple for me to see its uses. Couldn't you just use a dictionary, which also has key and value? Then I realized why dictionaries are fairly different. The lack of order in dictionaries means that you can't do certain things, like check every value in the same order every time. Although, you might be able to if you gave the keys integer values. However, the fact that nodes have their own classes allows for them to have their own properties, which can be very useful. For example, we can use built in functions like str, repr and eq for the nodes. We could also write more methods in the node class, like changing which node another node leads to. The more I thought about it, the more I realized how linked lists could be used, especially as the basis for more complicated code.

Friday, 6 March 2015

Week 7 so far

I guess I was wrong about posting this one yesterday. At least it's actually on time now! Our topic this week is supposed to be our impressions of week 7. I'm guessing they want use to talk about the topics discussed in lecture, which was mostly the abstract data type of Trees. I'm also going to write a bit about Assignment 2 and other things that went on in CSC 148.
Like most other students in the class, I spent a lot of time this week on Assignment 2. Also, judging by the Facebook group, most of them also had trouble with the Minimax strategy. One thing that made it difficult was how long it took to test it. I was able to test it with the Subtract Square game and test my Tippy game using the random strategy, but playing a full game of Tippy with the Minimax strategy took too long.
In lecture, we learned about Trees, which is an example of an ADT. A tree is composed of nodes, which may or may not have other nodes of children. Nodes that have children are internal nodes while ones without children are leaves. There are different types of trees. One example is Binary Trees, which contain two children at most. Tree nodes can be visited through recursion. A reason to do this might be to search for a specific value in the tree. Recursion would check each node, then check the children if the value isn't there.

Thursday, 5 March 2015

Abstract Data Types

Again, sorry for this really late post. Since it's already the week after anyways, I'm going to post the next blog post for this week today as well while I wait for my Assignment 2 to finish testing. I've already written about recursion and object-oriented programming, so I decided to write today's post on Abstract Data Types. I wrote a bit on it in my last post, but I'll try to make this one more thorough.

Abstract Data Types are data types that are defined by their properties and behavior. They have an interface, which refers to the mentioned properties and behavior, and their implementation, which refers to the how those properties and behaviors are coded. Since they're usually meant to be used by other programmers in their own code, it is the interface that is important, not the implementation. This also means that they can be implemented in many different programming languages with different algorithms. The programmer of the ADT might change the code for a reason. For example, they might want to make it more efficient. In that case, they have to make sure that the interface stays the same to avoid ruining other code that uses their ADT.

There are many commonly known ADTs. For example, Stacks and Queues. Stacks contain multiple elements and can only return the last element added. Queues also contain multiple elements but can only return the first element added. In Python these are easily implemented using lists. However, in other languages different methods might be needed. Another common ADT are associative arrays, where each value is associated with a key. In Python, dictionaries are used as associate arrays. However, in other languages objects might work better.

Wednesday, 18 February 2015

OOP concepts

Sorry for being even later with the post this week, I admit that I procrastinated due to reading week. It's been going good so far, but a train ride that was supposed to take 6 hours ended up taking 12 hours. Thanks a lot, VIA Rail.
The topic of this post is a summary of Object-Orientated Programming concepts. To me, the main ones we learned are Abstract Data Types, Inheritance and Recursion.

Abstract Data Types, or ADT, are data types that are defined by their attributes. It's not the implementation that's important, but the interface which allows others to know what the data type can do and what they can do with it in their own code. One example is Stacks, which are implemented in many different programming languages but has the same function in all of them. All of them hold an number of elements and can push -add a new element- or pop - return the last element added. Another example of an ADT is a Tree, which is represented as a tree structure of linked nodes.

Inheritance has to do with extending existing classes to make new classes and prevent having to write the same code multiple times. All classes already inherit from the Object data type, giving them certain functions. A second class can be written as a subclass of a first class, which means that it inherits all of its methods and attributes. Methods and attributes can also be overwritten in the subclass, which is when they are changed from the original class. One reason to use inheritance could be if you need to define different data types that still have much in common, like if you were writing data representations of shows that could all record their views, but wanted to write another class for specifically sitcoms that would could still record views but also stored the amount of times a laugh track was used. Sometimes in inheritance, the original class is known as an abstract class, which means that it is only used through it's subclasses.

Recursion is when the implementation of a function involves calling itself. It can be used to call a function many times until a certain result is returned. The last function call, where it stops calling itself, is referred to as the base case. Recursion can be used for many different reasons - it can be used to create geometric shapes, or add the elements in a set, etc. Recursion allows us to write less code that is more simple than if we hadn't used it.


Monday, 9 February 2015

Recursion

Today I'm going to talk about recursion and recursion tracing. Sorry for this post being late, I've been pretty stressful lately. But you probably aren't here to read about that. And if you are, that
wouldn't really make much sense. Anyways, on to recursion.
I've often recursion described as when a function is defined by itself. A basic example could be:

def count_total(lst):
    if not isinstance(lst, list):
        return lst
    else:
        return sum([count_total(i) for i in lst])

This function adds all the elements in a list, including elements in nested lists.  A comment on my last post asked how I would explain recursion, considering that its solving a problem using the problem. Pretty complicated stuff. The way I see it, it's like you're expanding a problem, or going deeper. In the example above, you call the function count_total on each element in a list, then call it on each list element in the list, and so forth until you get to the non-list elements. From what I've seen of recursion so far, there is always eventually a situation where you stop calling the original function - here, it's when an element is not a list. I haven't seen much recursion, but I'd imagine that you need that to happen unless you want the function to keep calling itself forever, like an infinite loop.

Recursion tracing really shows the expansion aspect - it reminds me of expanding polynomials in math. If we try the above example on the list [1, 3, [6, [1]], 4], we get:
    --> sum([count_total(i) for i in lst]
    --> sum([count_total(1), count_total(3), count_total([6, [1]]), count_total(4),])
    --> sum([1, 3, count_total(6), count_total([1]), 4])
    --> sum([1, 3, 6, count_total(1), 4])
    --> sum([1, 3, 6, 1, 4])
    --> 15

Recursion tracing seems to me like the kind of thing which seems easy at first, but can quickly get complicated and confusing. It is helpful when trying to understand why recursion code I'm writing doesn't work, but it's also a bit tedious at times.

Thanks for reading! Or if you just skimmed/skipped most of this and went to the end, well that's okay too. Everyone's busy, it's understandable.
  


Sunday, 1 February 2015

The First Few Weeks

The topic for this week is my impression so far of the first few weeks of this course. Honestly, I haven't found the class too challenging so far, though that is probably because we're still in the early stages of the course. The main points of interests are the first assignment, the labs, inheritance and recursion and the slogs.
The first assignment was confusing at first, but was easy enough once I understood what they were asking for. Everything needed for the assignment was taught in CSC108 besides inheritance and abstract classes. I think I did a decent job on it, though I didn't follow the style guides on some areas such as the requirements for whitespace. Having inheritance as part of the requirements meant that I thought more about the structure and the way it worked more than before. I had a bit of trouble writing docstrings. I wasn't sure what to write for examples that depended on randomly generated values.
I'm not too fond of labs. My TA is nice, but as the labs have been fairly easy so far I haven't had a reason to ask him for help. The exercises seem easy enough to do at home and coming to the lab for two hours seemed unecessary. Hopefully it becomes more useful as the material becomes more difficult. However, that wouldn't change the fact that I missed the free Lights concert on campus because of my first lab. And I love Lights.
I already knew about the concepts of recursion and inheritance, so they weren't really new to me. My knowledge of recursion is very basic though so I expect to get frustrated by them in the coming weeks.
Remembering to write slog posts has been one of the most challenging parts so far of this course. I also spent an unreasonably long time thinking of my slog url. Defying my expectations, apparently someone other than my TA visited my blog based on a very strange comment left on my last post. If you're reading this, Razarac00, well I don't actually know how to reply. Thanks for the comment, it was definitely unexpected. I do kind of like the idea of slog-hopping though.
Thanks for reading, TAs and possibly fellow students!

Saturday, 24 January 2015

Why Geeks should know how to write

This is the start of my slog for CSC148 winter 2015. Thanks to everyone reading this, so pretty much the one TA marking this.
The topic we're supposed to write about this week is why geeks should know how to write. First of all, there are reasons why everyone should know how to write. Writing is our way of communicating our thoughts to others, the world and sometimes even ourselves. Some are private, like when we feel like a swirling jumble of emotions and thoughts and writing them down gives us a way to make sense of it all.  Sometimes its our way of showing our thoughts and experiences to the world. It could be through a book, an article in a scientific journal, even a blog post. In these situations, its important to know how to write well. When we write well, we can convey our thoughts accurately. People will be more likely to read what we write well, letting us influence them more. With the internet, communication and writing are more important than others. Despite the grumblings of the older generation, nowadays, people probably read and write more than ever, albeit in smaller, more managable chunks.
The word geek can be used to mean various roles and stereotypes in society. Here, it will be used to mean people who work in the sciences, more specifically computer science.  People in the sciences are often stereotyped as being poor writers, thought of as having higher intelligences but with less creativity and social skills. We might not write as much as people in arts and humanities, but it's still important for us to know how to share what we create and discover. In programming, it can be hard for us to understand what others, and sometimes even ourselves write. Writing clear documentation is very important for anyone using the code in order to understand what it can do and how to use it. We also need writing to share new and better ways to do things so that others can also do things better and more efficiently.