Python in "math through programming" curriculum

Neelakantan Krishnaswami neelk at
Tue Dec 19 19:17:30 EST 2000

On Tue, 19 Dec 2000 10:24:56 +0100, Alex Martelli <aleaxit at> wrote:
> People who 'know' the very opposite -- that multiple paradigms widen
> one's mind, and are typically needed for rich, complex programming
> tasks in the 'real world' -- may still be rightly reluctant to give
> multi-paradigm exposure to students at the price of using a rich,
> composite, complicated language.  But Python lets you have your
> paradigms and eat them too...!-)

I disagree with you here about Python's appropriateness. Conceptually,
the strongly typed FPLs are the best languages there are for learning
about the mathematics of computer programming. The combination of
declaring algebraic datatypes and using pattern-matching to describe
functions is a brilliant leap forward, because it makes the
mathematical structure of the program very very explicit. (This is
amazingly apparent if you try to write an interpreter in ML.)

Python is weak in this regard because it makes sum types rather hard
to use: one must declare a set of classes and then give them all the
appropriate methods. This is rather scattered, and when you have
mutually recursive datatypes the relationships become much harder to
see. It's much better than C, or even Java, but still rather awkward
vis-a-vis any of the FPLs.

> Caml, IMHO, has rather cluttered syntax when compared to Haskell (or
> Python!); it only gets worse when the Object-oriented extensions are
> also considered.  Admittedly, a minor consideration, but, _for the
> specific issue of programming-newbies_, not a negligible one IMHO.

This is the *big* weakness of the ML-family languages (including
Haskell and Clean): they all have gnarly syntaxes. Python is proof
that a simple syntax is extremely important; it has essentially the
same semantics as Perl, yet I would gnaw off my arm to escape
programming in Perl and quite enjoy programming in Python. Random
syntactic clutter is really bad for novices; their brains are fully
occupied with the ideas, and trivia like the distinction between "and"
vs. "andalso" and when you should parenthesize expressions will only
distract them and make their lives harder. (Both are real examples
from SML.)

I think that if someone were interested in designing a beginner's
language, a Hindley-Milner typed FPL with a simple syntax (could be
parsed with an LL(1) grammar, say) would be a rather good target to
aim for. Python wins big in this category, of course. 


More information about the Python-list mailing list