Wednesday, January 2, 2008

Review: An introduction to python.

In an effort to actually write some content for this blog, I am going to start posting notes to particularly good books that I've read recently.


An introduction to python is the best book I've ever read on the subject of Python programming. It's a very short book - for a very short language. The biggest advantages to this book over the others intro books is the example code and explanations are pythonic, also this is one of the least expensive programming texts around.

Mind you, this book won't teach you to program. It won't teach you to deal with Twisted, or web.py, or any other library. This book will teach you the core Python syntax, semantics, and way of thinking. It assumes, quite strongly, that you have experience in programming. It assumes you're going to continue reading about framework x.y.z you want to use in python. However, it does what it sets out to do and it does a beautiful job.

If you set out to read this book, I suspect it will take you less than a day to finish (I finished in about 3 hours). So I'll provide a brief overview of some of the cool parts and why you should read this, but I'd recommend just buying it (it's cheap!) and reading it for yourself.

Chapter 1 and 2 are everything you need to know to get started using a python interpreter. Sum total of 11 pages, and not a single wasted screenshot of how to install it on platform x, y, or z. Readers would be well advised to note that ipython is a much better shell than the default implementation, but obviously a book on the language can refrain from saying things like that.

Chapter 3 is the standard "whirlwind tour" of the language, starting with a calculator and ending with while loops. There is little value to this chapter excluding syntax issues (if you come from another language).

Chapter 4 runs through the rest of the control flow syntax, a typical example quality is, after defining a working Fibonacci number calculator, they proceed to explain the basics of functional programming. If you already know how to program, this makes sense, if you only know Java this chapter might get a bit hairy.


<<fb
<function fib at 10042ed0>
<< f = fib
<< f(100)
1 1 2 3 5 8 13 21 34 55 89


With that, the core language you need to "get things done" is well defined by the time chapter 5 arrives on page 38. This manages to beat even Core Java 2 in succinctness.

Chapter 5 is the standard boring text on "we support these data structures out of the box." The primary value in reading this chapter is to memorize the pythonic syntax and read the examples for general ideas on how python code should look (and these examples are great).

Chapter 6 covers the module system. This is the most exhaustive reference on any module system in any introductory text ever. Not only does it explain the syntax for the module system, it explains several advanced features such as packages that were previously fuzzy to me.

Chapter 7 and 8 define basic IO and Exceptions. Neither of these were particularly interesting, and while they cover it well enough there isn't much else to say.

Chapter 9 covers objects is where the book really shines. This is probably the hardest to read chapter of the book, as it's a bit closer to a standard textbook than an introductory tutorial as has been going on. I think it's a good idea for everyone to read all the text -- no matter how much OOP you think they know. Unless you use one of a small set of unpopular languages, you don't think of objects the same way Python does. If you see this book in a store, "skim" this chapter thoroughly, it's well worth reading.

Chapter 10 and 11 cover the standard library in 20 words or less. I didn't find it exceptionally valuable, except that it came right after chapters 6 and 9, cementing those ideas in my head. The material in this text is more of a introduction to modules in the Standard Library... to help you find more documentation about them.

The rest of the book is mostly appendixes. While short, this book managed to help me understand what the word "pythonic" means. The prose is very approachable, and the examples are well justified. Universally the code in this book is of high quality, and this book jump starts a developer to be a Python developer. Also, it's really cheap, and well worth the money.

Moving on, "The Python Language Reference Manual" fits this book like chapter 2. I'll be reviewing it sometime shortly.

1 comment:

Anonymous said...

My comment is actually a response to your comment here: http://schwuk.com/articles/2008/1/16/bestseller#comment-768

If you want to write a book and let someone else worry about publishing, etc, use the same publisher that David uses: Packt.

Go here and browse through all the links on the left of the page:

http://www.packtpub.com/authors

(Apologies for the slightly OT post, but at least I found a book-related post to comment on :-)