Your impression of for-novice writings on assertions
Raymond Hettinger
python at rcn.com
Tue Feb 2 16:22:55 EST 2010
On Feb 2, 12:54 pm, "Alf P. Steinbach" <al... at start.no> wrote:
> 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.
To my eyes it reads nicely. You may want to try it out on a real
beginner to get their feedback.
I like your section on assertions. You could add examples of other
ways assertions can be used (loop invariants, sanity checks, post-
condition contract checks). For example, validate a loop invariant
during a selection sort. In the hypot() example, use an assertion for
sanity checking by verifying an expected mathematical relationship
such as the triangle inequality: assert abs(c) <= abs(a) + abs(b).
The pythagorean triple example can use assertions to check post
conditions: assert all(isinstance(x, int) for x in (a,b,c)) and a*a
+b*b==c*c.
Raymond
More information about the Python-list
mailing list