Saturday, January 31, 2015

SLOG Post #2 - Tracing Recursive Functions

This week in class we learned about recursion. According to Wikipedia, a recursive definition is something that is "used to define an object in terms of itself". We were looking specifically at recursive functions, which are functions that call themselves in their own definition. These sorts of functions are very useful when working with arbitrarily-nested lists. For example, you can define recursive functions that can sum all of the numbers in an arbitrarily-nested list of integers with very few lines of code, while other methods would be difficult and involve relatively complex code.

Our lab this week focused on tracing recursive functions that took progressively more complex arguments. We were encouraged to not show every step, as the Python visualizer would, but instead build upon information that we had already confirmed. For example, if we already confirmed that the function worked on a non-nested list, we could use this information in later examples that involved nested lists (of varying degrees). I found this sort of work to be somewhat challenging. It was easy for me to determine how the function would work and guess the correct return value. However, showing how the function got to that value was a lot more difficult. I was often unsure of how many steps to show, because I was not able to identify which steps were most important. However, after looking at many examples and trying many practice questions, I think I've gotten pretty good at it.

The other major focus of this week was Assignment #1, which was due on Thursday. When I first looked at the assignment description sheet, I had no idea what the assignment was asking for or how to do it. However, after consulting Piazza and re-reading the notes from the lectures, my partner and I were able to get a general idea of what to do. We started off working on the GameState abstract class by thinking of attributes that all game states would share (such as whose turns it is, if the game is over, etc.). We then went on to create the SubtractSquareState subclass by filling in the areas that could not be covered by GameState. We went through a similar process with the abstract class Strategy and our strategy subclass RandomMoveStrategy (the strategy of randomly choosing one of the available legal moves). After we had finished these classes, we worked on class GameView, which was used to facilitate communication between the user and the game state and strategies. the game view took the longest to finish, as we often had to go back to GameState and Strategy and change things to make the overall program work better. We also had to be very careful with our style (in particular, our docstrings and examples). Even though we started the project a week in advance, we ended up working right up to the deadline (we submitted it at 9:45 pm!). I feel that the work with the numerous docstrings was quite tedious, although I understand why this kind of work is important. My overall impression of Assignment 1 is positive: I think we learned a lot about object-oriented programming and inheritance, and I also think that we did a pretty good job.

Wednesday, January 21, 2015

SLOG Post #1 - Why Should Geeks Write?

January 22 2015


I think it's important for geeks to write because writing is an essential form of communication between human beings: it's one of the most basic ways that we communicate our ideas to others. In fact, I personally see programming as a form of "writing" as it allows us to instruct and interact with machines.

Programming and the written word have much in common. Like programming, writing was once confined to the educated elites and intellects. But as the complexity of our societies grew, the ability to read and write became more and more accessible to the masses. Most developed countries have literacy rates above 95%, and the people who are denied access to this fundamental means of communication are at an insurmountable disadvantage.

The same can be said for mathematics, the language of logic. In the past, only the philosophers and stonemasons were able to communicate with math, but now it is an essential part of our daily lives. Driving, taxes, home renovations, cooking, living expenses... all require at least a basic level of numerical knowledge. Furthermore, most young people today have some understanding of more advanced concepts in math, like calculus and vectors. As a society, our fluency in math is increasing with every generation.

I am of the opinion that programming is the next form of communication that will become mainstream. Only 40 years ago, this language was limited to the geekiest of geeks: the mathematicians and telecom engineers and university professors (kidding!). Nowadays, programming has moved from being ultra-geeky to something that’s pretty normal, and kind of cool. Digital technology plays a huge role in our lives today, and being able to manipulate and improve the machines that we interact with is becoming more and more important. It's only a matter of time before children in kindergarten are being taught the difference between integers and floats, to complement their lessons on addition and the ABC's.

There are also many practical reasons for a programmer to have good writing skills. We often need to complement our computer code with written explanations, in the form of docstrings or #comments, so that other humans can understand what we are doing and why we are doing it. More complex programs might even require a manual or report that goes into greater detail. Furthermore, many writing skills,  such as checking for spelling/grammar errors and editing to improve clarity/conciseness, are also very important for coding. 

Fundamentally, programming and writing (and mathematics) are all different ways of expressing ideas. Sure, they each have their formats and required skillsets, but they all contribute to our ability to communicate. Just because programming is a newer form doesn’t make it better or worse than the others: all forms of communication are important, and it is for this reason that I believe that geeky programmers should also be competent writers.