[Review] Learn to Code by Solving Problems – by Prof. Daniel Zingaro

In this article, I’ll review the book “Learn to Code by Solving Problems: A Python Programming Primer” by Prof. Daniel Zingaro. The book is available here:

This is an independent review. I didn’t include any affiliate link, so I won’t get compensated if you decide to purchase the book. Although I know Daniel personally, I’m not affiliated with him in any way. My publisher NoStarch asked me to write a review about this book—without any form of monetary compensation.

Most people judge a book by its cover, although their mothers told them not to. Here’s the beautiful cover:

Let’s start with the book review. I decided to use a relatively strict form for the book review by providing ratings from 1 to 5 stars for different categories. The final score is an average across the category scores.

About the Author – 5 Stars

Is the author qualified to write a programming book? Let’s examine this first!

Daniel is a computer science teaching professor at the University of Toronto. His daily work centers around computer science education. As a professor, he has taught thousands of students how to program. He won awards for his teaching endeavors. Even his Ph.D. research focused on how to teach programming more effectively.

Clearly, it’s tough to find an author who is more qualified to write an introduction to programming book. Is Daniel qualified to write this book? Yes!

5 out of 5 stars. ⭐⭐⭐⭐⭐

Book Idea – 5 Stars

Is this a unique book or just another Python introduction? Let’s dive into this question next!

The book idea is simple: the reader is guided through 25 programming problems, each with the same structure:

  1. Explain the programming challenge on a high level.
  2. Specify inputs and desired outputs.
  3. Provide relevant background information.
  4. Discuss the solution.

This is an active learning teaching technique.

Many programming books simply repackage the official Python documentation and the reader is often left alone wondering “Why am I even learning this?“.

Zingaro’s book is different. It prepares the reader to absorb the newly learned information by making them aware of what they don’t yet know. In contrast to many other programming books, Zingaro’s book doesn’t simply try to cram as much random information as possible into the reader’s head.

  • Steps 1 and 2 first open a knowledge gap in the reader’s mind.
  • Step 4 discusses the solution, a natural step that guides the reader through a series of eureka moments where they can compare their own solutions with that of a programming expert and, thereby, close their knowledge gap.
  • Step 3 is one of the central pedagogical devices in this book. The author could have chosen to discuss the solution right away. However, this would have kicked the reader out of the “active learning” loop. Without preparing the solution, newbies wouldn’t be able to solve the challenge themselves. But thanks to Step 3, beginners are enabled to develop their own solutions. Intermediate and advanced coders can skip step 3 to increase the challenge.

Overall, I think the format, structure, and book idea are well-developed. The book makes the objective “solving problems” a first-class citizen, which leads to better learning retention and faster understanding of the material. It also teaches students the art of thinking for themselves.

As a bonus, readers learn to solve problems which prepares them for programming interviews by tech companies. Hundreds of thousands of coders go through these interviews every year, and this book is a great way to prepare for those interviews in Python.

To summarize, the book’s idea is simple yet powerful. The book is a handy and straightforward introduction to Python programming and problem-solving skills. It is not particularly novel as many books have chosen a similar format. But even though the book idea is not rocket science, it wouldn’t make sense to penalize it for using a proven and effective learning method.

5 out of 5 stars. ⭐⭐⭐⭐⭐

Technical Execution – 4.5 Stars

Is the book well-written? Does it contain a lot of technical material? I try to shed light on these questions next.

Zingaro’s new book is a well-structured, thoroughly-edited Python textbook that obviously went through several rounds of editing. You won’t find a lot of grammar, spelling, and technical mistakes. The fact that it is written with the most successful Python publisher in the world, NoStarch, is evident on every page.

A common problem, even with professionally edited Python textbooks, is that they often violate the PEP8 coding standard in many instances.

When reading through the book, I realized that although the code is clean and simple, it could be slightly improved in terms of being more “Pythonic”. For example, the following code solution is given on page 214:

# Main Program

for dataset in range(10):
    n = int(input())
    addresses = set()
    for i in range(n):
        address = input()
        address = clean(address)
        addresses.add(address)

    print(len(addresses))

A Python expert would probably compress five lines into a single one using set comprehension:

# Main Program

for dataset in range(10):
    n = int(input())
    addresses = set(clean(input()) for _ in range(n))
    print(len(addresses))

I’d consider this as more Pythonic in two ways:

  • It is shorter and more concise, and
  • It doesn’t define variable i that is not needed.

However, I don’t think it would be fair to deduct rating points either because the author wanted to demonstrate the difference between set.add() and list.append(). This couldn’t have been done as explicitly using the more condensed code variant. So, in most instances I found, the author chose to write less idiomatic code to avoid confusing the reader.

Another instance is given on page 226 where the code for inverting a dictionary is given:

if not num in inverted:
    ...

A slightly more readable format, and the one recommended in this section of PEP8, would be:

if num not in inverted:
    ...

But these slight imperfections in the code do not weigh heavy: the overall quality in terms of writing, technical depth, and code is exceptional.

4.5 out of 5 stars. ⭐⭐⭐⭐💫

Summary

The book is an exceptionally well-written technical Python book for beginners that uses active learning techniques. If you’re a beginner to intermediate-level coder, this book will significantly improve your Python skills. It’s easy to read, and solving the problems is fun and satisfying.

The overall rating is:

  • About the Author – 5 Stars
  • Book Idea – 5 Stars
  • Technical Execution – 4.5 Stars

So, the overall rating of the book is 4.8 out of 5 stars. Let’s make it ⭐⭐⭐⭐⭐. An almost perfect book for Python beginners and intermediates alike!