Ask HN: ______ is to Python as K&R is to C?
I'm in need of a book recommendation for learning Python (not learning programming, just adding this language to my repertoire).
My learning method is more "start coding something, and refer to a reference book frequently" than "do these lessons and you'll eventually learn enough to start coding something you actually care about". A good reference is dense and to the point; it makes it quick and easy to look up both the syntax of individual features, and the thinking behind them.
Basically, my ideal programming book is Kernighan and Ritchie's "The C Programming Language" -- I want that, but for Python.
52 comments
[ 3.2 ms ] story [ 121 ms ] threadMy other two references are the Python Standard Library Docs (http://docs.python.org/library/index.html) and StackOverflow.
"The book is weird, uses antiquated technology, has horrible examples [...]"
Dive into Python has code examples which use ODBC:
"He has a [...] book that purports to teach people programming that still, in 2010, references a piece of crap technology from the 90's. Yes, he actually used that technology to teach Python in the beginning of his book six years ago. [...]
Meanwhile, Mr. Pilgrim's book hasn't been updated in 6 years even though it's [...] online and people can send him patches. [...]
Dive Into Python isn't just bad because of the use of ODBC, it's also just full of bad initial examples. Take a look at your first Python program and boggle at all the bizarre stuff a beginner has to suddenly comprehend:
- A function, with a giant doc comment right away.
- Weird underscore variables with a bad font making it look like one underscore.
- A list comprehension for-loop to join a string using a format string off a tuple.
- A dict, formatted with backslash chars that aren't even needed.
Holy crap, how in the hell is that a good first example? Even worse is it starts a trend within the book of using ODBC as a theme to teach Python."
Edit: Snipped strong language.
(The parent, now deleted, was referring to http://learnpythonthehardway.org/ which a couple of other posters also link to.)
Other good books are:
* Learn Python the Hard Way -- http://learnpythonthehardway.org/index
* How to Think Like a Computer Scientist/Think Python (now Python for Software Development) -- http://www.greenteapress.com/thinkpython/
Dive Into Python is good, but IIRC (from Dive Into Python 2), Mark Pilgrim tends to use very convoluted solutions to simple problems. The solution might be superior in terms of performance, but don't always help you learn the language.
I never fully grokked Ruby's object model until I read that book.
I reread it often and always discover/re-discover useful information.
The coverage, speed and size (half the size of Pickaxe book) make you productive quickly.
The closest thing to K&R C for python is Python Essential Reference by Beazley. The structure mirrors K&C. The first chapter is a "tutorial introduction", basically a quick survey of the language, followed by about 150 page explaining the language. It is dense and terse and to the point. The remaining 400 pages are a reference for the python library.
Having a book is like having an additional monitor full of information that is uncompromising on your task. It's also wonderful to read, and easy to pop open even when your laptop isn't out, and you're just curious "I wonder if Array has a method to do ...."
A final note, because of that, having a paper reference (especially an annotated one) lends itself strongly to actually reading large swaths of it, instead of just finding the method you need and putting it away. With it being clunky, you don't want to do a lookup twice, so you open it and keep it open, and often read through a module/class' entire method list. That really improves your knowledge.
So in short, because it encourages good work and work practices.
This is probably pretty intentional. I had Dave as a professor for several C based classes and he recommended K&R highly. In the introductory course, he even used it as the textbook.
(btw I also have attended one of his new Chicago Python classes - recommended, he's a great teacher)
If you were to find a K&R for Python, then it would be missing an important something which is unique to Python - an acknowledgement and appreciation of absurdity.
[edit: was "good humor"].
I'd say use the official docs combined with a cookbook or "learning python" book (which is pretty big).
K&R got to be K&R because C really didn't change that much.
I bought "Learning Python" because it covers both 2.x and 3.x, but found it absolutely unnavigable as a reference. It might work well for people who want a tutorial they can go through step by step, but for someone who just wants to quickly find and absorb info in the process of doing something else, it doesn't cut the mustard.
"It's not even a very good way to learn C. The idioms and best-practices for C programming have evolved substantially, even since the second edition was published, and some of the code samples look a bit dated." And this is from 2004, meaning it got even more dated.(http://sites.google.com/site/steveyegge2/ten-great-books)
The reason K&R is still the canonical C book is because it represents the language better than any other book, before or since, not because the language stagnated since ANSI C was created.
I find that makes it wholly in adequate for thinking in C anymore. The "Never trust data" mantra which is now part and parcel of C dev is not at all shown in K&R.
Definitely recommended for learning Python fast&practically. It's the most comprehensive and useful Python reference book for programmers I've ever encountered.
For example, compare Programming Perl (aka the Camel book) to K&R, the former is a long, didactic, journey through Perl's linguistic building blocks, while the latter is a laconic, technical, concise guide to C. I think these also embody the philosophy and nature of these languages. Another example would be Lisp/Scheme books that tend to be academic, and theoretical.
I recommend "Dive Into Python" to people who want to start to get a taste of Python, but anybody that has developed a appetite for Python and wants to really, really Grok how Python works, I recommend O'Reilly's "Learning Python" and tell them to take the time to read it cover-to-cover.