Wednesday, 16 December 2009

What makes a programming language easy to learn?

This is something that I've been thinking about for a while.  I can't claim to have any deep insights or to have conducted any rigorous research, but intuition plus the anecdotal evidence from over twelve years of teaching programming to undergraduates leads me to suggest four principles that a language should follow:
  • Minimal redundancy
  • Separation of concerns
  • Minimal surprise
  • Appropriate complexity
Minimal redundancy essentially means that a language should avoid having many similar ways of achieving a particular goal - interestingly, the opposite of the well-known Perl mantra "There's More Than One Way To Do It". Having unnecessary, redundant features means that there is more for students to learn, for little material benefit. Teaching only a subset of the language won't help matters, because students will inevitably come across the features you omit via other sources such as textbooks, websites found via Google, etc - and this creates uncertainty as to which is the 'best' way to do something.

Separation of concerns is the counterbalance to minimal redundancy.  Whereas it is desirable for a language to keep syntax and features to a minimum, this should not be done to the extent that very different concerns are dealt with using the same syntax or language feature. In essence, a language should avoid overloading its syntax with different, context-dependent meanings if possible, because this can cause unnecessary confusion, make code harder to read, etc.

Minimal surprise means that, where possible, a language should behave in a manner consistent with the normal expectations of the novice programmer.  Surprising behaviour forces the learner to expend extra mental effort to process and understand what they are seeing; furthermore, it can have a detrimental effect on programmer confidence.

Appropriate complexity means that small, simple tasks should be achievable with small, simple programs; moreover, small increases in the size and complexity of a task should result in correspondingly small increases in program size and complexity.

In forthcoming blog posts, I'll expand on each of these principles and give examples of how well Python conforms to them in comparison with another language that is used in higher education :)

Tuesday, 15 December 2009

System usage monitoring with Django

I haven't blogged about Django in a long while - partly because I've been too busy doing other things, such as using it to create a real web application (as opposed to the personal web apps and teaching apps that I'd previously written).

The real web application in question is a system to analyse usage of a commercial virtual learning environment (VLE) deployed at a higher education institution.  This VLE is large and heavily used, as the following stats from the 2008-9 academic year indicate:

  30,000+ users
  258 million hits against web server
  1.9 million logins from students
  Average of 6,200 logins per day, (peaking at 20,000)

Our system is able to determine the type of student that has logged into the VLE.  It also uses built-in knowledge of the local network plus GeoIP data to identify where logins are coming from.  Information on the time and location of login and type of student are stored in a database, and Django is used to provide a web-based interface to this database.  The results of queries are presented to the user in various forms - typically as tabular data (paginated if necessary) plus a chart of some sort if appropriate.  We use matplotlib to generate pie charts, bar charts and time series charts, plus the Google Chart API to produce maps showing the countries from which students are accessing the VLE when they are away from university.

In future blog posts, I'll go into more detail about how it all works...

Saturday, 12 December 2009

The one that wasn't a game...

Following on from yesterday's post about the recent graphics programming assignment done by my first-year students, it is worth noting that one of our students was adventurous enough to implement something other than a game.

Alex Hawdon wrote a very interesting program that invokes p0f to analyse incoming attempts to establish TCP connections with your machine, interprets IP addresses using a GeoIP database and then serves up the results as a KML file over HTTP - the latter then being monitored via Google Earth, of course.  The net result: a 3D, real-time visualisation of attempted hacks against your machine.

Friday, 11 December 2009

Game Demos

Yesterday was the demonstration session for our open-ended graphics programming coursework.  The students seemed to enjoy themselves - even to the point of turning up in suitably festive clothing:


The aim of the whole exercise was to develop something in Python that involved dynamic graphics. We didn't require it to be a game, but almost everyone chose this option - probably because we devoted several lectures and one of the lab classes to explaining how Pygame could be used for this!

There were some very impressive submissions.  Ian Kernick (pictured above) and Sean Watson - the self-styled 'S & I Productions' - gave us Nazi Zombies: a third-person shooter with suitably gory graphics and sound effects.  So polished was this piece of work that it even had its own movie intro!  One notable feature was the layering of sprites to create a pseudo-3D effect in which the player could move behind or in front of the zombies.

Zombies were also the main enemy faced by the player in Alex Hawes' game, but this time the player was moved around using an XBox 360 game controller.  Ed Worthy used a similar control mechanism in his Geometry Wars clone - all the more impressive for being apparently implemented from scratch in a marathon all-night programming session right before the deadline!  I'd love to see what he could have done with better time management...

There was plenty of other good work on display.  Julie Tillier showed us a very complete and playable PacMan-style maze game and Minos Galanakis demoed a ballistics game in which the player controlled the angle and speed of a projectile fired from a cannon.  Projectile motion was governed by realistic physics and the player's score was synchronised with a high-score table stored externally on an FTP server.

It was common for students to take their inspiration from existing, often very familiar games.  In addition to those examples mentioned above, we saw a decent effort at implementing a Guitar Hero clone (driven by key presses rather than the authentic guitar-shaped controller, regrettably) and also a Frogger-style game called Intoxication, in which the protagonist was a student evading heavy traffic to drink pints of beer that appeared randomly at the roadside!  Hmm...

We rather liked an unusual-looking game from Stefan Piazza and John Lau, called Bit Defence.  It had colourful, distinctive vector-style graphics and was notable for being a two-player game, with multiple levels and power-ups.  The player-controlled sprites had to orbit around a central disc-shaped zone that they were defending, as well as rotating so that they were always facing outwards.  A lot of thought had clearly gone into how this motion could be smoothly and efficiently animated.


Saturday, 5 December 2009

Python's Moratorium

Jesse Noller has posted a thorough and well-reasoned explanation of Python's recently-announced moratorium on new language features.  I'm surprised that people are grumbling about the moratorium, but it is good to see a well-argued response to the critics.

I'm very keen for us to standardise on Python 3.x in our teaching at Leeds, but the (understandably) slow pace of transition to the new syntax for some of the large third-party packages and frameworks that we use (e.g., Pygame, wxPython, etc) has meant that we've been reluctant up until now to make the commitment.  My hope is that we'll see greater enthusiasm for making the '2 to 3' transition, now that Python is not going to be a moving target for the next couple of years.

Of course, this is a community where we should all pitch in and help to make change happen - so I'm not going to sit back and wait for others to do all the work.  I just have to figure out where I can make an effective and useful contribution...