Saturday, 28 February 2015

Reconsidering Recursion - Week 7 (Mark this!)

I already wrote about my impressions on recursion, but I figured it has been given enough focus in class and labs to warrant another post. As I talked about earlier, I think that the reason recursion is initially unintuitive is because it feels like the problem you are solving is not precisely resolved by the code you write. What I mean is that, until now, the code we have written has been written to directly perform some function or solve some problem. With recursion, since the data structure being considered is typically arbitrary in nature (eg. a list with unknown depth, a tree with unknown branches and children), we are unable to know exactly what we are working with.

To deal with this, we define what we want the function to do when it reaches a base case, typically after the most simple object in the data structure has been reached (eg. working down a tree to get to a leaf, reaching the objects contained in a list of arbitrary depths). If we have not reached the base case yet, the function executes a different line of code, typically asking the function to recursively perform itself on objects within the original data structure. As long as the base case has not been reached, this code continues to execute.

Considering the approach listed above, it appears that the initially unintuitive nature of recursion is due to the fact that the solution is often simpler than the problem itself. Since the problem itself can be infinitely complex by human standards, it is typically counterproductive to consider the problem as a whole and instead think about how the problem is structured; what is the simplest case and how the problem can become more complex. Instead of directly telling the function how it is going to solve the problem, you are defining how the function will navigate the structure of the problem, since this structure can be extremely simple or infinitely convoluted.

Knowing this, the usefulness of recursion is even more apparent. It is a type of problem solving where considering the problem as a whole can be overwhelming and the structure itself is more important. You are not solving the problem per say, you are providing the function with an algorithm by which it will navigate and solve the problem. As we begin to consider slightly more complex recursive problems, like in assignment 2, I am sure an economic approach to coding will be more important than ever as increasingly large problems exponentially increase the amount of code that needs to be processed. Therefore, any attempts to make the code more efficient may lead to drastic differences in processing time as large problems are considered.

Monday, 16 February 2015

Object-Oriented Programming

Being my first programming language, I initially did not have that great of an understanding of what it means to be an object oriented language. Of course, I understand the concept of objects becoming tangible instances of the abstract classes and functions we write and how these can be stores as variables to store or manipulate data (probably wrong on a technical level, but it makes sense to me for now).

However, recently out of boredom I decided to look into the process of designing an app for iOS. I'm not sure if I'll ever design one. I was just curious. To my surprise, Apple's new programming language (related to Objective-C, if I remember correctly), Swift, is already entirely intuitive to me. There are a few different conventions, such as declaring variables by prefacing the new variable name with "var" and I'm sure there are many concepts unique to app or program development that I have no conception of yet. But everything I learned about defining functions, classes, methods (including special methods), heritability, and so on translated effortlessly. What took me a full half course and part of CSC148 to learn in Python took me an hour to learn in Swift. Even though I lack the truly intuitive understanding of OOP and its relationship to other styles of programming, it's clear to me now that the concepts that make it up are easily transferable between languages.

The prompt this week is particularly vague and I think I lack the perspective of being fluent in non-OOP languages to really appreciate the concepts of OOP. However, it seems like, in a nutshell, the idea of OOP is to create robust 'structures' (or objects) such as functions, classes, and methods, to be as diverse and useful as possible for a variety of scenarios. When specific problems are needed to be solved, concepts such as heritability allow us to focus in on these situations without losing the more broad schematic (basically, superclasses and subclasses). This sort or preparation on what to keep abstract and what to define later one is very interesting to me and I can imagine it being all the more important as our assignments and problem solving becomes more complex and larger in scale.

Saturday, 7 February 2015

Impressions on Recursion

I think the problem of counting the elements of a list, which are organized in varying depths, is an interesting one because it is a very simplistic problem with a very, initially, unintuitive solution. Up until now, we've been programming for very consistent and concrete parameters, so being faced with a problem involving arbitrary parameters (and I mean the depth of the list argument, not function parameters necessarily) is kind of frightening as it's not immediately clear how to approach it.

Luckily, more intelligent minds have done the work for us and thus we learned recursion. Now, different problems still require fairly differing solutions so it is not exactly a plug-in-the-numbers solution (and I assume recursion will be used for much more complex tasks). But the idea of calling a function on itself seems like cheating or rule-breaking or outside of most people's consideration. So being introduced to a new way of thinking about how functions interact was quite intriguing (and partially terrifying, thinking of the complex problems to come).

Like most logical solutions, it makes sense once you see it written down and tracing, though still confusing at first, is easy enough if you tackle it one item at a time. It'll be interesting to see what happens once we are asked to create our own, novel recursive solutions...
My First Few Weeks

First of all, I haven't been posting on schedule. I don't really have an excuse for that other than being busy and it slipping my mind but hopefully this will make up for it and I'll keep on schedule from now on.

As the first term test approached, I realized something. I didn't really have any notes to go through. In CSC108, I created notes for every video, referenced them, studied them, etc. In CSC148, during class, I mainly just payed attention in class and played around in Wing101 to see if I understood it. So instead, I went through the past labs and skimmed through the class slides. That's it.

Now this isn't because I was lazy or Winging (hah) the test. My point is that 108 was very focused on teaching us all of the basic concepts of the course. Methods, classes, importing, loops, operators, etc. In 148, we are still using the same tools. What we've been doing in class is just learning how to apply it in novel, interesting ways and that's what I have enjoyed about this course thus far. In a few weeks, we've used classes to create an entire game, thinking about the concept about abstract classes and which classes should draw information from which and how to leave room for further addition of games.

While it's not wildly more advanced than what we did at the end of 108, it has really helped me realize exactly how these tools are implemented in more practical, large scale projects (not that our assignment was large, but the concepts of creating abstract classes for example). Luckily, I've been keeping up with the material and felt very comfortable with the assignment (although the jury's still out, I don't have my mark back yet haha). I guess what I'm saying is: I realized that 148 teaches you, in some ways, how to think using the tools we've already learned and by the time, the test came around, I already felt confident with most of the material we've discussed until that point.