Sierpinski gaskets, and how to teach graphics, objects, classes, and recursion visually

Ghana Summer 2012 Blog

Written by: Alessondra Springmann

June 27, 2012

It's been a long while since I took my first programming class (fall 2006), taught by the excellent MIT alumni Lyn Turbak and Mark Sheldon.  Their curriculum was inspired by Allen Downey, whose book, How to Think Like A Computer Scientist, has been 'ported' to Python and C++. Even though the class was taught in Java, the focus on larger ideas and concepts is astoundingly portable as well, allowing me to pick up MATLAB and Python without too much trouble.

One of my favorite aspects of Wellesley's introductory computer science course was the focus on graphics as a way to visualize what code was doing.  Jovana last night was mentioning she wanted to introduce the students to graphics in Python, and I suggested displaying a Sierpinski gasket (a fractal and an attractive fixed set; triangles drawn within triangles) as a visual example.  "What's a Sierpinski gasket?" We're lucky to have good reception in our apartments to use our movistar modems with local Vodafone SIM cards; a quick Google and Jovana was off creating a fantastic lab for the program participants.  (Apparently there are connections with the math behind this triangle and the Towers of Hanoi problem.  Who knew?!)  A few hours later she'd cooked up a great lab to demonstrate classes, objects, recursion, and yes, graphics to the AITI students. When they finish writing their code and setting their triangles to render, their screens display something like this:

A Sierpinski gasket in the process of being drawn

In terms of technical content, we provided an introduction to Python last week, getting up to functions.  This week saw the introduction of data structures (with local tropical fruit as examples of items to be in a list... let me tell you the pineapple here is a revelation in fruit consumption) as well as classes and objects.  I learned over the weekend about using a dictionary while calculating values in a Fibonacci sequence... great if you want to save time, not so great if you want to save memory.  Yesterday's lab introduced string methods for objects, and a FootballTeam class (since we're at the tail end of the EuroCup and Jovana is a huuuuuuge football fan).  What methods would you want to have for keeping score, maintaining a team roster, or knowing where the team would play next?

A lot of students haven't programmed before, or have taken computer science classes that are mostly theoretical.  Being asked to take a concept from one example and applying a similar solution to a different example is really hard for them!  Talking with a friend (an MIT '11!) who works in engineering and science education here, it sounds like a lot of Ghanaian school curriculum involves memorization of facts (algorithm solving) rather than learning through doing, or coming up with solutions on your own (algorithm generation).  

With 43 students and two technical instructors, it's really difficult to reach all of our participants who are struggling and make sure they're not too far behind the ones who finish the labs quickly and move on to more challenging problems.  I haven't been doing much Python as of late, so my ability to explain self in the context of classes and objects isn't going to do them much good!

The ones who do get the new concepts and language are doing so very rapidly.  We're excited to introduce Django next week and see what sort of web apps they can build!  Hopefully the network connections here in the ICT Directorate building are up to the challenge.  

On that note, I would like to make a big shoutout to Google: thank you for creating webapps that gracefully handle spotty network connections.  Gmail and Google Docs are doggedly persistent in transmitting data when the network is flaky, and the ability to at least view offline Gmail and Docs has been really nice.  Some other cloud-based apps simply don't work here---it's been very frustrating to reach out to their support people and be told that I need a better network connection to use a web app I pay money for; they should all take a page out of Google's book.  If you're going to fail, fail with grace and style and leave the customer something that's actually useful.  Thank you.