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 :)

No comments:

Post a Comment