- Last edited on Feb 28, 2017, 7:58:53 AM by 100297 Martijn Pieters
This is an unordered collection of issues members of the sopython community have found with the book Learn Python The Hard Way. We noticed a general trend that users using LPTHW post questions that don’t make a lot of sense both on SO and in chat. This is due to the structure and techniques used in the book. We recommend these tutorials instead. If you’d like to discuss this more, come chat!
- Repeatedly asks the reader to ensure that the reader uses Python 2, stating that Python 3 will not be in general use for a long time.
- Can have a quite condescending tone.
- Even the Python 2 version is out of date. Uses Python 2.6 in the examples.
- Exercise 3 on math does not talk about the rounding behaviour, about the
from __future__ import division, or anything for that matter; details are left for the reader to find out. “Notice the math seems "wrong”? There are no fractions, only whole numbers. You need to use a “floating point” number, which is a number with a decimal point, as in 10.5, or 0.89, or even 3.0.“
- String formatting (Ex 6) just explains the
- Ex 10 tells about Unicode escapes, of course without telling what the Unicode is or how to do it in Python.
- Does not teach
withfor processing files
- Calls functions commands until teaching the word function. Likewise modules are features until they are called modules.
- First teaches the concept of command line and command line arguments and then (much later) proceeds to explain functions as some kind of miniscripts that take arguments akin to
- Ex 23 again says: ‘Avoid any project that mentions "Python 3”. That’ll only confuse you.’
- Asks to memorize truth tables for Boolean ops, calls this “better than trying to understand it”
- Really backwards teaching order, files taught before any control structures.
- Ex 31 says this about testing whether a number falls into a range: “Use
0 < x < 10or
1 <= x < 10, which is classic notation, or use
x in range(1, 10).” And this is Python 2. Even in Python 3 the
O(n)for floats and most probably would fail.
- Ex 37 - review - passingly mentions
yieldin a table, that weren’t taught in previous exercises. Nor were the concepts of generators, iterators or even exceptions.
.next()is used to get the next value from a generator.
- After teaching methods in 38, Ex 39 teaches dictionaries and… how to build a hash table class?!
- “Ex 40: Classes are like minimodules, objects are like mini-imports.”
- Ex 41 defines “composition” as “The concept that a class can be composed of other classes as parts, much like how a car has wheels.” and then immediately defines “attribute” as “A property classes have that are from composition and are usually variables.” This isn’t even wrong.
- Ex 43 teaches non-pythonic stuff, like picking a random item from a list with
randint(0, len(x)-1)instead of suggesting
- Ex 45 says “method is a function”.
- Ex 46 teaches writing a package. Up until then the keyword arguments are not explained. A dictionary of arguments to
setupis built, then applied with
- Exceptions are finally taught in Ex 48, after the setup script. This is the first time a string is converted to an integer and exceptions handled appropriately.
- Uses recursion excessively, teaching users that chaining a series of functions to build a game is somehow good code flow (without ever talking about what this means in terms of the call stack).