Your impression of for-novice writings on assertions

Peter peter.milliken at
Wed Feb 3 02:21:14 CET 2010

On Feb 3, 7:54 am, "Alf P. Steinbach" <al... at> wrote:
> I've started on ch 3 of my beginner's intro to programming, now delving into the
> details of the Python language.
> It's just a few pages yet, file [03 asd.pdf] (no real title yet!) at <url:> which is at Google Docs.
> The first topic is about assertions and exceptions. I wonder whether this text
> is easy or difficult to understand for a beginner. Or any improvements that
> could be made.
> Cheers,
> - Alf

The only issue I have with what is there is the example - most
programmers are not interested in solving mathematical equations and
the code is enough to make the reader go cross-eyed. IMO the example
code tends to detract from the point you are trying to make about
using and how to use assertions.

I would suggest a much simpler (to read) example than the one given.
Ideally I would like to see more than one example with the examples
graded from simple to more complex. A simple example could be just
using the assert statement to verify pre-condition (assumptions) made
on parameters to a function i.e.

def divide (x, y):
  return x / y

The programmer obviously assumed that y will never be 0 - so with one
simple example you teach two points:

1. how an assert can be used
2. when programming look for unconscious assumptions


P.S. You also raise an interesting issue in my mind when quoting Knuth
and siting TeX as an example application with no known bugs - Knuth
advocated and used literate programming when writing TeX to achieve
"clarity". I believe he (still?) cites the fact that TeX is so bug
free because he used Literate Programming to write it (well, at least
one reason). So should we be trying to teach literate programming to
beginners? You did open that can of worms by quoting and siting Knuth
and TeX... :-)

More information about the Python-list mailing list