We've been on a mission since last week to get exposure to the test-driven as opposed to the test-sometime so tonight we find ourselves at the offices of Fry-IT in Southwark, London watching at least two Python gurus doing Code Dojo. It's reassuring to see recognised developers halted by unfamiliar editors and settings on an operating system few here have used regularly, no matter how pretty Mac OS might be.
We witnessed a Randori Kata:
A challenge is set and solved by pair programming (driver and co-pilot). Each pair has a small amount of time to advance the solution using TDD. When the time is up the driver goes back to the audience, the co-pilot becomes driver and one of the audience step up to be co-pilot.
Folks took it in turn driving/co-politing to create a social network graph using Graphviz based on Twitter friend/follower data. For someone who'd seen maybe five lines of Python (and ignored four of them) prior to this evening, this was a nice introduction to the language as things progressed at a nice, gentle pace. Whilst getting up to speed one helpful guy pointed out his Interactive Python Tutorial written in Silverlight. Nice.
It didn't take too long to see out why the language has become so popular. Take Fibonacci:
def fibonacci():
a, b = 0, 1
while True:
yield a
a, b = b, a + b
Compared to the C# 3.0 implementation it's utterly readable
Func fib = null;
fib = n => n > 1 ? fib(n - 1) + fib(n - 2) : n;
The Python version fares even better than the C# 2.0 version
static int a = 0;
static int b = 1;
public static int DoFib(int num)
{
int temp_value;
if (num < 2)
{
a = 0;
b = 1;
}
else
{
DoFib(num - 1);
temp_value = b;
b = a + b;
a = temp_value;
}
return a;
}
Pretty good for a first code dojo; I took along a proper Python Developer to decipher some of the odd-looking, intellisense-free text appearing onto the projected screen. The next Python Coding Dojo is on in October and by then we may even have written something in Python. Baby Steps.