Your impression of for-novice writings on assertions

  • Thread starter Alf P. Steinbach
  • Start date
A

Alf P. Steinbach

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:
http://tinyurl.com/programmingbookP3> 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
 
R

Raymond Hettinger

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
 
I

Irmen de Jong

I've started on ch 3 of my beginner's intro to programming, now delving
into the details of the Python language.

Alf,
I think it's a good read so far. I just don't like the smilies that
occur in the text. It's a book (or article) that I'm reading, not an
instant messaging conversation.

Irmen
 
S

Steve Holden

Alf said:
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: http://tinyurl.com/programmingbookP3> 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.
I don't think it's helpful in Python to refer to "... variables, which
are named locations in memory, ..." because Python specifically eschews
this model, and trying to explain assignment (especially of mutable
objects) in those terms will lead to conceptual difficulties.

Also, why introduce exceptions by talking about "error handling" when
the term "exception handling" is hanging in the air? This is also a
conceptual thing, since you want to get the reader used to the idea that
it's a legitimate programming technique to use exceptions as part of
their programs' normal control flow.

I'd also recommend taking docstrings a little more seriously, since
their use makes code much more self-documenting - someone can import
your module and learn its API using the help() function. You may have
done that in an earlier chapter.

Just a few points for you to think about, and reject if you choose.

regards
Steve
 
P

Peter

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:http://tinyurl.com/programmingbookP3> 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

Peter

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

David

Hi Alf,

I think you talk too much... :) Basically I am all for a verbose
approach in a text for beginners, but on the other hand it is necessary
to stick to the point you are making.
When, for example, you introduce your reader to the thoughts of Francis
Glassborrow on page 5 of chapter three, then the only relevant point you
are making is the following: "Many programmers hide the structure of
their code behind their comments [which is to be avoided]". If you
insist on a proper citation here, then use a footnote, but even there I
would suggest you merely offer the link. As it stands you are not to the
point, and frankly, as a beginner I have enough stuff troubling my head
so that I do not need superfluous information as to the evolution of the
things you are talking about. Just the facts, please.

My 2 cents,

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top