17Sep
artwork depicting a stylized cover of "Learn Python the Hard Way)
A (hopefully unbiased) review

When starting to learn a new skill — say, a programming language — people often turn to books as they provide the most insightful material. Novice Python programmers are no different — lists of popular courses and books (like ours, for instance) can always provide some valuable insights. In Python community, one book has gained a lot of popularity throughout the years — Learn Python the Hard Way (also called ”LPTHW” for short).

Python community, however, feels somewhat conflicted about this book — it’s praised for a fresh teaching style, but also criticized for a number of reasons. A few years ago, I started my journey into the world of Python with this book — and now I’ll share my personal thoughts on it. Although it’s tempting to share an opinion, I’ll try to present both good and bad things about this book and avoid oversimplifications like ”Yeah, it’s good, go buy it” or ”It’s trash, run from it!”

In this article, we’ll explore the personality of Zed A. Shaw (the book’s author), as well as outline its structure, see its exercises, and analyze its good and bad aspects. After that, make sure to check our Python interview questions out.

Disclaimer: Like with any book, it’s impossible to state whether it’s objectively good or bad. The strong and weak sides of Learn Python the Hard Way I’ll outline in this article are subjective, so you might find the book’s pros insufficient and its cons blown out of proportion. If that happens to be the case, the comment section welcomes your feedback. 🙂 We all learn differently, so addressing my criticism of Learn Python the Hard Way if you disagree with it is very important

About the author

photo of Zed A. Shaw
Yep, that’s Zed!

Zed A. Shaw is an experienced software developer known for his Ruby applications (most notably, the Mongrel webserver), tech articles, and educational projects (e.g. a series of ”Learn Code The Hard Way” courses). However, he owes his popularity not only to his books and projects; Zed is also an outspoken critic of certain technologies and aspects of the programming culture.

The most striking example is his disdain for Python 3: in his blog post (or, rather, an essay) titled The Case Against Python 3 (For Now) written in November, 2016, Zed outlines the problems that Python 3 (allegedly) has been designed with a number of fatal flaws — his quote There is a high probability that Python 3 is such a failure it will kill Python is a good summary of his sentiment.

As you can probably tell, Zed’s criticism of Python 3 was reflected in Learn Python the Hard Way — and this lead to another chain of criticism (now of Zed) from Python 3 supporters. In the sections below, we’ll learn whether Zed’s radical approach was justified.

Structure, Focus, and Topics

artwork depicting a stylized cover of "Learn Python the Hard Way)
Our article’s protagonist

Learn Python the Hard Way is a book that — spoiler alert! — teaches you Python and attempts to teach the programming mindset in general. While the path to learning a given programming language is quite clear (Understand the language’s pros, cons, and use cases → Learn its syntax → Delve into the intricacies of how it performs), teaching programming as a problem-solving skill is far trickier: the student needs to learn how to think like a problem-solver.

Chapters breakdown

The book starts off with an elaborate Python setup guide (written both for Windows- and macOS-based machines) that helps the reader to install the tools they need and ensure that they’re working properly. Then it’s finally time to write some Python code — here are the topics that the author covers:

  • Chapters 1-14 are dedicated to printing, strings, and variables.
  • Chapters 15-17 detail how to work with files: read, write, and copy them.
  • Chapters 18-21 introduce functions.
  • Chapter 22 suggests that the reader scans previous chapters and prepares a list of all symbols that they’ve used — and spends the next 2 days testing their knowledge of those symbols (e.g. ‘, %, \, =, etc.)
  • Chapters 23-25 serve as a practice-heavy refresher of all previous chapters.
  • Chapters 26 is a test designed to test the reader’s debugging skills: Zed provides Python code with mistakes and asks the reader to fix it.
  • Chapters 27-31 introduce Boolean logic and if-statements.
  • Chapters 32-36 dissect various types of loops.
  • Chapters 37 is a symbol review, providing a neat little cheat sheet for Python keywords, data types, string escape sequences, and operators.
  • Chapters 38 and 39 cover lists and dictionaries.
  • Chapters 40-49 explain Object-Oriented Programming.
  • Finally, Chapters 50-52 serve as a brief introduction to web development with Flask.

What makes Learn Python the Hard Way great

artwork depicting an open book
But not perfect

For a number of years, this book has been one of the most common recommendations for Python newbies. Let’s take a closer look at the factors that allowed for the book’s popularity.

“Learn it yourself” approach

The way Zed approaches the teaching process is rather unusual: throughout Learn Python the Hard Way, the reader is expected to find a lot of information independently. The author simply points in the general direction (Read about the setup.py file and all it has to offer, for instance) and hopes the reader will understand everything they dig up online.

On the one hand, this provides a great introduction to the world of programming, as if saying: ”No resource will be able to answer all of your questions — you have to learn to find the answers by yourself. Read the docs, check other tutorials out, ask around — and you might manage to finally come up with the solution. This is the way of programming, young padawan!”

On the other hand, however, this teaching style irritates a lot of people — we’ll explore its negative side effects in the Controversies and Criticism section.

Introduction to the command line

Realizing that ”programming” doesn’t solely refer to ”writing code”, Zed includes an appendix chapter titled Command Line Crash Course, designed to serve as a brief introduction to the world of consoles and terminals. Some developers may argue that the knowledge of command-line interfaces isn’t that important, but I would say this: If something can protect you from the old ”Just run rm -rf to solve the problem, buddy!” prank, then it’s definitely useful!

In all seriousness, CLI knowledge is a great skill that any Python developer can benefit from — working with Git, managing virtual environments via pipenv, managing system performance via console utilities like iperf or htop… Even though it’s not a full-blown course, it provides the reader with a solid understanding of how CLIs work and how they’re different from GUIs; the lessons include:

  • Working with paths, folders, and directories (via mkdir)
  • Navigating around the filesystem (e.g. ls, cd, pushd/popd)
  • Working with files (e.g. touch, cp, mv)

Finally, Zed provides some neat cheat sheets for both Unix Bash and Powershell.

“Common Student Questions” sections

Realizing that many readers would encounter various bugs, mistype, and make other mistakes, Zed includes a ”Common Student Questions” section in every chapter. As the name suggests, it explains how to solve the most typical problems that readers might encounter — this is, essentially, Stack Overflow baked directly into the book! Here are some examples:

  • What’s better, ‘ ‘ ‘ or “ “ “? It’s entirely based on style. Go with the ”’ (triple-single-quote) style for now, but be ready to use either depending on what feels best or what everyone else is doing.
  • How come I get SyntaxError: invalid syntax whenever I run pydoc? You aren’t running pydoc from the command line; you’re probably running it from inside python3.6. Exit out of python3.6 first.
  • Why does for i in range(1, 3): only loop two times instead of three times? The range() function only does numbers from the first to the last, not including the last. So it stops at two, not three, in the preceding. This turns out to be the most common way to do this kind of loop.

Price

It’s free! Still, there’s an abundance of free Python learning materials nowadays, so a free product doesn’t stir as much excitement as it used to. Additionally, we’re starting to judge free stuff more and more harshly.

Controversies and Criticism

artwork depicting an open book
But not terrible

LPTHW is praised by many programmers, experienced and novice ones alike — it’s easy to see why after reading the previous section. However, it’s also criticized by an equal number of people: a quick Google search on “Learn Python the Hard Way” shows that many aspiring Python developers became disappointed with the book, especially after checking other learning resources out.

The “Python 2 vs. Python 3” debate

The ”2 vs. 3” debate often finds its way in newbie questions like ”I’m a beginner, should I start with Python 2 or Python 3?” — and experienced developers (supporting either version 2 or version 3) are always ready to start a heated discussion. Learn Python the Hard Way is Zed’s product, so he’s free to state his opinion in his own book; however, we as the readers should fact-check the information that the author broadcasts. Let’s explore Zed’s stance in detail.

In Exercise 0: The Setup, he says:

A programmer may try to get you to install Python 3 and learn that. Say, “When all of the Python code on your computer is Python 3, then I’ll try to learn it.” That should keep them busy for about 10 years. I repeat, do not use Python 3’. Python 3 is not used very much, and if you learn Python 2 you can easily learn Python 3 when you need it. If you learn Python 3 then you’ll still have to learn Python 2 to get anything done. Just learn Python 2 and ignore people saying Python 3 is the future.

The quote above comes from the year 2014 when the latest edition of Learn Python (2) The Hard Way was published. As a book author and a developer, Zed has always heavily criticized Python 3 and prophesied that it wouldn’t take off. This radical opinion is fitting for a post in a personal blog, but priming tens of thousands of new programmers to use an older technology, knowing full well that support for Python 2 would end in 2020? This doesn’t sit well with me — the author should have also acknowledged why more and more developers were switching to Python 3.

In the ”About the author” section above, we’ve established that some of Zed’s dissatisfaction with Python 3 may be justified. Now, we can take a closer look at what other developers think: JetBrains (the team behind PyCharm, one of the most popular Python IDEs) holds annual Python Developers Survey to observe and analyze the trends in terms of Python’s popularity and usage. Their latest report holds a lot of valuable insights, but we’re mainly interested in the ”Python 3 Adoption” section. Using JetBrain’s data, let’s visualize the ”2 vs. 3” debate:

statistics showing the difference in adoption of Python 2 and Python 3
Where’s Python 1, though?..

We can also examine the rate at which Python 3 gained popularity:

statistics showing the difference in adoption of Python 3
To the moon!

The data shows Python 3 has been on a constant rise throughout the years — and ignoring this trend didn’t make any sense in 2016. Thankfully, in 2017, Zed finally made the decision to update the book to Python 3.

Teaching style

Ironically enough, the “Learn it yourself” approach that Zed utilizes in his book backfired and became a major point of criticism — the question that many people ask is as follows:”Why did I pay ~$30 dollars for a book that tells me to learn stuff elsewhere?”

This dissatisfaction is completely justified: Zed often tells the reader to “Go read about…”, “Research why…”, ”Find other people’s code…” when it comes to important Python concepts and modules. If he asked the reader to familiarize themselves with command-line interface on YouTube, that’d be fine — CLIs aren’t exactly a part of Python. However, the book is called ”Learn Python the Hard Way” — but it doesn’t provide enough content for learning.

Repetition

LPTHW involves a lot of typing — Zed warns the reader against copy-and-pasting code snippets. Instead, they are expected to type all code manually which is supposed to help them remember Python constructs.

Even Zed himself calls this process a boring, mindless memorization — and many people agree. Here’s the question: Is Python’s syntax so difficult to remember? It’s a well-known fact that programmers don’t really have to remember every fine detail — they only need to remember the source where they can look a given detail up. Zed, however, forces the reader to memorize everything via manual typing. While this approach does work for some people, it’s not self-evident that it’s efficient for every novice programmer.

(Over)simplification

The book does serve as a great introduction to Python, but it’s a subpar introduction to programming — in many cases, when Zed presents the reader with a computer science concept, he explains it much later, dumbs it down, or decides not to explain the concept at all.

Here’s a typical scenario: you’re inputting neat little commands that make your computer print ”Hello, world! My name is…”; suddenly, you type def… and the font color changes. Zed tells you to disregard it, type another 20-30 lines of code, and forget about that weird def keyword (he explains it in the following chapter, though).

Here’s my favorite example: Zed shows you some code and tells you: See if you can figure out what it’s doing. And he never explains it!

Lack of exercises

Although the chapters in this book are called ”Exercises”, it’s hardly a fitting name because real exercises are few and far between here. I personally put great value on exercises that provide a precise end goal without holding the student’s hand too much — they unleash our creativity via forcing us to find the solution.

To showcase an example of a good exercise, we can turn to another book for beginner Python programmers called Think Python, written by Allen B. Downey. Here’s one of the exercises after the ”Dictionaries” chapter:

If you did Exercise 10-7, you already have a function named has_duplicates that takes a list as a parameter and returns True if there is any object that appears more than once in the list. Use a dictionary to write a faster, simpler version of has_duplicates.

In Think Python, each chapter offers a number of exercises, ranging from easy to hard; each exercise is designed to teach you how to solve a real-world problem. The scope of these problems, of course, isn’t large; nevertheless; these simple operations form the basis of more complex programming operations.

In Learn Python the Hard Way, however, the so-called ”Study Drills” (which act as exercises for each chapter) sometimes don’t really provide any hands-on experience. Here are the study drills found in Chapter 47: Automated Testing:

  1. Go read about nosetests more, and also read about alternatives.
  2. Learn about Python’s “doc tests,” and see if you like them better.
  3. Make your room more advanced, and then use it to rebuild your game yet again, but this time unit test as you go.

Conclusion

In defense of Learn Python the Hard Way, however, I should also reiterate this point: There is no ideal learning resource. Typing code manually and learning core concepts without the book may actually work for some people — and you might be one of them. If you’ve read this book and have some feedback to share, the comment section awaits you!

Managing Kubernetes using Terraform

Kubernetes has continued in its strive to influence the tech space with its flexibility and portability in container orchestration. And with its continuous strive, there has been an increasing need to connect, configure and manage Kubernetes with other tools and resources of your choice. This has brought about the creation of more automation products, infrastructure, and features to satisfy this increasing need.

Leave a Reply