String formatting

22 Jul, 2019

Lou O writes:

Hi Jason, Read a few good reviews of your book on Amazon.
One of the reviews pointed out "The explanation of String formatting needs to be updated. We don't do embedded values using %s anymore. I recommend skipping the chapters on Turtle Graphics and tkinter. The introductory chapter on classes and objects is not bad, but the topic is beyond what most kids will need, and they should really focus on imperative / procedural programming first using just lists and dictionaries as their basic data structures."
And I was wondering if those points had been taken into account and updated since then.

In terms of string formatting, the reviewer is correct but, on the other hand, % formatting hasn't actually been deprecated yet. From the official Python 3 documentation:

The formatting operations described here exhibit a variety of quirks that lead to a number of common errors (such as failing to display tuples and dictionaries correctly). Using the newer formatted string literals, the str.format() interface, or template strings may help avoid these errors. Each of these alternatives provides their own trade-offs and benefits of simplicity, flexibility, and/or extensibility.

I have thought about updating the section on formatting though, just because using str.format is the more accepted/modern method -- but this will probably have to wait for a second edition, or perhaps the next major reprint.

In terms of classes and objects, I don't agree at all. When originally writing the book, I thought rather hard about whether it was worth going into the complexity of that topic and, in the end, came to the conclusion that there is too much in Python which is object-oriented, and would be more confusing to explain without at least covering the basics (IMHO).

And finally, in regard to the comment about skipping the chapters on turtle and tkinter... sure, if they want a dry book on programming fundamentals, with nothing fun for a kid to experiment with -- one that they will then put down 10 minutes after opening and never return to -- by all means, skip those chapters.

For everyone else: will your child use the turtle and/or tkinter modules in the future? Probably not. But are they a useful tool to learn how to use those fundamental programming concepts (without needing to install any complicated third party libraries)? Personally, I believe so.