Questions and remarks on Python for Kids

19 May, 2014

Marcin S writes:

I am currently testing your book on my girlfriend who is not a kid anymore but a person that has not written any code in her entire life. To assist her better I have read the whole book. I think I spent my money well when I bought it.

Still, I have some questions and remarks.

Did you consider to emphasize more we are using Python 3 in the entire book? I know that the reader is instructed to download that version, but if someone uses Python 2 for some reason (e.g. computer science classroom with outdated software), one will get different results. In the context of your book I have found two important cases: 1) division always produces a float in Python3 because we no longer have a strict difference between integers and floats, 2) input() works like raw_input() from Python2, while input() in Python2 made implicit eval(). [1]

The errata mentions input() behaves differently than readline() depending on the context -- console or shell. I am unable to replicate it. BTW, the parameter to read()/readline() specifies the maximum number of characters to read, not the exact number. And there is one more thing -- if one reads less characters than available on stdin, remaining characters will be read on the next call to read()/readline(). [2]

Are strings enclosed in triple double-quotes omitted as reserved for documentation? I think only triple single-quotes are mentioned in the book. [3]

Why did you choose to name classes with plural names (class Giraffes) instead of singular (class Giraffe)? [4]

The "is" keyword is mentioned in the keywords section as a complicated concept and is omitted in the examples. I have one remark on that: PEP8 suggests using "is" when checking if something is None (not with "=="). [5]

I have seen range() with 3 arguments mentioned later in the book. Did you consider mentioning slices ([a:b:c]) as well? [6]

Did you consider mentioning "for" and "while" with the optional "else" block? [6]

The book mentions random.choice() but the bounce game uses shuffle() and picking by index instead. [7]

Mr. Stick Man checks for collisions using comparisons glued with "and". Did you consider constructs like "x1 < x < x2" instead of "x1 < x and x < x2"? [8]

Why did you choose a Tk construct based on sequence: update_idletasks(), update(), sleep() instead of mainloop() with rescheduling with Tk.after()? There would not be any active wait then and it would be event-driven. Is not the update_idletasks() included in update()? [9]

I've annotated your comments so I can address each in turn, but the answer to many of your points is somewhat similar:

[1] No, at the time of writing, I didn't consider more emphasis was needed, other than what is detailed in the first chapter. But as time has gone on, the differences between 2 and 3 account for a significantly large percentage of the questions I get about the book, so perhaps something additional makes sense.
[2] The problem is reproducible in Python3.2 (and older versions). In 3.3 onwards, the max characters parameter works as expected.
[3] No, the triple double-quotes were omitted essentially for simplification reasons. To make it less confusing for younger readers.
[4] I chose plural class names mainly to try to indicate class as a kind of grouping - trying to distinguish between that and singular object instances. Yes, not particularly standard, but I had a (possibly vain) hope it would help to highlight the difference between class and object.
[5] "is" was omitted again for simplification reasons -- to avoid a complicated description of how object identity works.
[6] Again, slices and else blocks in for/while loops were omitted for simplification.
[7] You'll find a description of the shuffle function on page 136.
[8] Another one omitted to simplify things. Combining conditions with and and or is, I believe, more straightforward for kids to understand (even if x < y < z is a bit cleaner)
[9] This one came up in the review from one of the technical proof readers. mainloop is definitely the better (read as correct) approach, but I wanted to stick with a loop and update/update_idletasks because it made it obvious, to the reader, what is happening. Each loop tells one of the objects to do something (move and draw), and then triggers Tk to redraw the screen (the reason for using both update and update_idletasks is that when writing the book -- with an earlier version of Python3 -- I saw some animation jittering when using only the one call. Using both seemed to resolve that issue. Perhaps I should've checked why at the time, and maybe it's no longer an problem with Python3.4)

Hope that helps clarify some of your questions...