Sunday, 9 March 2014

Pair Programming

The course requires us to work in groups during lab time and we are encouraged to team up for Assignment work.  The technique of pair programming is used in professional settings and involves the programmers to alternately take on two roles: that of a driver, who inputs the code and that of a navigator, who monitors the code for errors.  The technique is beneficial in terms of efficiently writing code, the navigator spots bugs before that are buried in multiple lines of code and before they require hours of sifting through.
In a professional milieu, the pair is matched in terms of knowledge - they are able to communicate effectively about what their goals are and how they want to achieve them.  I also imagine that they work together for an extended period of time and are bale to develop a relationship and to find ways to complement each other's skills.
Pair programming in a classroom setting presents a few challenges. In a school setting, when people are starting out at different levels of knowledge, and are just starting to get used to working in pairs, group work becomes more complicated.  There are a few things one can do to make the pair programming experience easier:

- Talk to your piers.  Find out what their level of skill is and whether they are good communicators.  It is important to be able to talk to each other while completing assignments.  Find someone who is excited about the work you will be doing together.

- Pay attention to the way your partner works.  There is always something to learn and you should be able to spot their mistakes more easily if you know what to expect.  

- Do not be hesitant to share knowledge.  You will both benefit because teaching a skill to someone else (putting it in words so another will understand)  allows you ta take on a different point of view and thus to improve your own way of doing things.

- Spend time actually doing proper pair programming.  it is all too easy to divide the assignment work and go your own separate ways.  The goal, aside from learning to program, is to learn to work with other people.
  
- Become friends.    Working on assignments will not be a chore if you have fun together.

Saturday, 1 March 2014

Recursion

Recursion involves iterating over smaller instances of a complex problem to provide a solution. A recursive function repeatedly calls itself in its definition in order to produce an output. As is the case of a while loop, there needs to be a base case in order to prevent the program from running infinitely.
In class, we were introduced to recursion using the example of this function:

sum_list:

return sum([sum_list(x) if isinstance(x, list) else x for x in L])

The base case in this function is the if isinstance(x, list) stipulation. It tells the program to keep running the sum_list function on itself until it gets to an element of the nested list which is not itself a list, in which case it runs the sum method.

If the sum_list function encounters a list while traversing over the given input, it calls itself until a non-list element is encountered.

While manually tracing recursion, it's good to solve the simplest case of a problem first (a simple list of two elements, for example) and to note the results in further tracing of more complex problems (like a nested list of two levels.)