Tuesday 17 February 2015

Week 6

Apologies for the late post! Reading week has begun quite busily and I did not get a chance to post until now.
Object-oriented programming now feels quite intuitive, as we have had a fair bit of practice already. Whenever we need a "thing" in our program, we create a class and an instance of that class that has all of the traits and abilities that we want for our "thing." So far, we have been told to include str, repr, init, and eq methods for any class we create, though I am not too certain why this is necessary. Danny, our professor, says that it is good etiquette to include such methods in a class, but sometimes it seems rather unnecessary. If programmers are "lazy," as Danny says, why should we include methods that are not of use to our program? This seems like an invalidated use of space. Another point I am not too clear on is what we want the output of our repr method to be - this seems like an alternate form of str, which is automatically used when no str method is present. To my knowledge, we could make the repr method output be whatever we wanted, as a representation of the object in a particular class. On my assignment, however, a note was that the repr should return something that can be pasted into the shell and have it create the specified object. I do not remember ever having learned this, nor having seen it in any examples. I would prefer to know in advance so that I do not make a similar mistake in any future assignments or in the rest of my career.

Sunday 8 February 2015

Week 5

Last week was our introduction to recursion. We were told that this is a widely useful concept in programming, and already began to experience this for ourselves during the lab. So far, we have mostly been tracing recursion, as opposed to writing our own code, though the lab did include one such question. Surprisingly, by the time my partner and I had finished tracing all of the examples, we did not have too much trouble implementing our own recursion to find the maximum length of a list from the input. I will want to practice writing docstrings for recursion, as I currently still find them a little tricky to understand and create myself.
When tracing recursion, I have found it helpful to write the steps out by hand. This allows me to carefully analyse each step and understand what the code does, so that I can ultimately correctly determine the output.
Though this is not an easy concept to wrap my head around, I am confident that I can quickly become more comfortable with recursion with a bit more practice.