Review of Allen B. Downey’s book Think Python. Python Basics»

Writing a good Python tutorial is hard. Perhaps more difficult than in any other programming language. Oddly enough, due to the fact that Python is a universal, widespread and very simple programming language.

Let’s figure it out. Python is called a language with a low threshold of entry for a reason: explaining the basics of syntax to a beginner is easy. The main thing is to correctly count the indents. And for those who already had programming experience in other languages, try to forget about all sorts of begin, end, curly braces and do not forget to put colons. By learning the syntax constructs, anyone can start writing simple programs in Python.

At the same time, Python is a language with a very developed “syntactic sugar”. Almost all tasks on it can be solved in several ways. And each of these methods is good in its own way. In fact, this is a wonderful property – everyone can choose syntactic constructions to their liking. But it will be very difficult to teach all these options to a beginner.

Imagine that you are writing a Python tutorial. You have well thought out the structure of the sections, built the logic of the story. You start adding examples and then, like a harmful devil from a snuffbox, this very sugar pops up in front of you. Which of the solutions to choose as the main one? What options should be given as additional? And what to use in the following examples? All these questions are sure to arise before every author of a Python textbook. If you do not find the answer to them, then the textbook will turn into a series of endlessly branching descriptions of options for solving the same problem.

Python is also a very versatile language. It is easy enough to move from simple programs to complex ones. Almost anything can be programmed in Python. And if you think about it, then absolutely everything. To solve any popular task on the network, there is a ready-made module that can be quickly downloaded using a simple command. The main thing is to know what to download. After that, with just a few lines of code, you can reverse rivers and move mountains. Create your own web server, design a Telegram bot, build a neural network for recognizing your cat’s mustachioed face in photographs – before, solving such problems was inaccessible to beginners.

Python has opened Pandora’s box – now anyone who has learned the basics of syntax can feel like an all-powerful developer. Unfortunately, it is to feel, not to become. After all, when on the way of such a “professional” a task arises for which there is no ready-made module, he will not know what to do. Each author should understand that the reader of his textbook has probably already seen enough articles on how to create your own small Universe in Python in 5 minutes. After that, he will sincerely wonder why they are trying to make him understand the difference between mutable and immutable data types. Indeed, when constructing the Universe from ready-made cubes, this will not be needed.

So writing a really good Python tutorial is pretty hard. But Allen Downey, professor of computer science, seems to have succeeded. Imagine that Python is not a programming language, but a foreign language that we need to learn. Of course, one cannot do without the study of syntactic constructions and constant replenishment of the vocabulary. But this is not enough. In order to really learn a foreign language, we will sooner or later have to start thinking in that language.

This is what Allen Downey teaches readers. Not in vain book originally called ThinkPython. The subtitle of the book is “Learn to Think Like a Programmer.” The author sets himself a difficult task: not only to teach the reader a new programming language, but also to tell him about the main methods, concepts and development techniques. In the end, the syntax of the language can be found in reference books. But they won’t help you learn how to program. And without this, learning any language is a rather pointless exercise.

Sometimes a good book can be described simply by listing what it doesn’t have. So, in the “Python Fundamentals” book, there is no:

  • descriptions of popular third-party modules;

  • recipes on how to make something in 5 minutes;

  • GUI application development techniques (with the exception of the ubiquitous turtle – the turtle module).

If the reader really wants to learn a new programming language properly, then all of the above will greatly interfere. After all, only having studied the basics – if you want, the “philosophy” of the language – you can move on. Omnipotent modules, enchanting interfaces, universal cross-platform – all this will come later. To begin with, you need to dive into those theses that are displayed by the import this command.

But don’t think that Allen Downey’s book has only dry theory that usually precedes practice. Just practice in the book is more than enough. Moreover, from the classic “Hello, world”, the reader quite imperceptibly and rather quickly moves on to tasks that he would not even dare to think about solving before reading the book. How do you, for example, develop a program that analyzes a text file with some book and, using Markov chains, composes a new text using the dictionary of this book? An example like this is a great excuse to explore tuples.

Rest assured, the author of the book has an interesting exercise for learning any aspect of the Python language. If you study the turtle module, which is mandatory in such cases, then you will draw with the turtle not just some boring rectangles, but the letters of the alphabet and the Archimedes spiral. And in the next chapter, why don’t we draw one of the most famous fractals, the Koch curve? If you are familiar with the concept of a function, then instead of boring calculations, try to find a solution to the equation of Fermat’s Last Theorem.

True, it was not without traditional platitudes. In every second book about Python there is a passage about the correct pronunciation of the word tuple (tuple). Couldn’t resist this and Allen Downey. On the other hand, this is quite interesting information, suitable for a first Python tutorial.

As you know, a programmer is not the one who writes programs. A programmer is someone whose programs work. Allen Downey understands this very well – it’s not for nothing that he has been teaching programming to students for many years. Therefore, at the end of each chapter of the book “Python Fundamentals” there is a subsection “Debugging”. There, the author talks in detail and consistently about code debugging techniques. Along the way, he introduces readers to such concepts as refactoring, tracing, debugging code.

There is a glossary at the end of each chapter listing all new terms. For example, there are definitions of such terms as composition and encapsulation. It seems to me that this is a very correct approach: first, explain to readers the meaning of a concept or object in simple language, give examples, and only then give its formal definition in a dictionary.

Another advantage of the book is in the chosen style of presentation. The author communicates with the reader not as a lecturer and not as a compiler of a reference book, but rather as a fellow guru who knows the programming language well and wants to tell you about it as simply and clearly as possible. Even hippopotamuses sometimes code in Python these days.

That is why the book is simply interesting to read – sequentially, page by page. Even if you take it to read away from the computer, somewhere on a park bench, you will not be bored – the story is captivating. And you can do the exercises later, at home at the computer.

Here is what the author writes in the first chapter: “The single most important skill for a developer is the ability to find a solution to a problem. To do this, he must formulate the problem, be creative in finding a solution, and then accurately and clearly implement it. This is the skill that Allen Downey’s book teaches. And the way to achieve this goal is to learn the Python programming language, which is ideal for this. If you want to not only learn Python, but really learn how to program, this book is perfect for you.

The article was first published elsewhere on June 8, 2022.

Similar Posts

Leave a Reply