Sunday, January 25, 2009

Programming in Python 3: A Complete Introduction to the Python Language: A Book Review

Author: Mark Summerfield Format: Paperback, 552 pages Publisher: Addison-Wesley Professional; 1st edition (December 26, 2008) ISBN-10: 0137129297 ISBN-13: 978-013712929 I wasn't particularly happy when I heard that Python 3 wasn't backwardly compatible with previous versions of Python, but I tried to keep an open mind about this. When I heard that Programming in Python 3 was being published in Addison-Wesley's Developer's Library series, I saw a chance to get up to speed quickly with what had changed. I don't code on a daily basis, so my skills wax and wane, depending on how often I get the time to work with a programming language and, unfortunately, it doesn't take long for me to become "oxidized". I was interested to see how Summerfield would approach this book, published just barely a month after Python 3 itself was officially released. Would the approach be as a strict reference guide for the experienced Python user looking for what had changed, or would there be something within the pages for people trying to learn Python for the first time? The answer, or at least part of the answer, was found in the first few pages of the Introduction. Experienced Python users will be happy to know that the book works to explain what practices they may be accustomed to using in Python 2, will no longer be necessary (or productive) in Python 3. New Python users will be happy to know that the author's intent is to completely teach the Python language, rather than just offer information on what has changed in the latest version. I say "complete" with the caveat that not all of the Python libraries are represented in this book. Hopefully, that won't short circuit even the complete Python newcomer since, once they've gotten some experience in that arena, the reader will know how to access and use any of the standard Python libraries. Summerfield and Addison-Wesley have thrown a really wide net over the entire topic, and the book claims to have something between its covers for everyone, from the curious student to the most experienced developer. That's a pretty tall order, and every book that says it is all things to all people, runs the risk of having to prove it. Many times, books that say they cover "everything" are found to cover certain areas well while other areas are only sparsely presented. One thing I was looking for from this book in particular, was the ability to write some productive, or at least emotionally satisfying scripts, fairly quickly. Nothing is more frustrating when trying to learn a language from a book, than to be able to do no more than echo back "Hello World!" when you're 140+ pages into the book. I'm all for learning concept and agree that you can't be very productive with a language if you don't understand what's under the hood, but on the other hand, programming is about making something happen. That said, the first thing you learn after finding out how to install Python 3 (not as easy as you might imagine, depending on your OS platform), is learning "Hello World!". Once past that, Chapter 1 does a couple of nice things. First, it introduces the reader to the basics of programming which is a plus for the new learner (though will likely bore the experienced coder to tears), and starts the reader out right away with using Python 3. The differences aren't earth shattering, but they exist and, if you are going to learn the latest version, you should learn it from the ground up. The end of each chapter does what I wish more "learning" books would do; presents a series of exercises for the reader to reinforce the material presented in the chapter. You'll never learn a programming language unless you get your hands dirty, hit a few dead ends and, occasionally want to beat your head against the wall (but only a little). The other thing that learning books need to do is provide the answers to all exercises somewhere at the end of the book, just in case the reader gets stuck. Fortunately Summerfield and the Developer's Library series does both of these things. Another nice little feature about the book is that, if a topic is mentioned on a particular page, there's a reference to where else in the book you find information on that topic. That saves a lot of page turning and frustrated index consulting. The writing is linear and progressive, which is exactly what I need as a learner. Summerfield isn't going to win awards for comedy writing, but he's not amazingly dry either, so the 552 pages of this text are quite readable. Beyond the introduction to programming in Python 3 in the first chapter, if you progress through the first six chapters in sequence, you'll be well on your way to taking off with using Python independently. Actually, I'd recommend going up through at least Chapter 8 before taking off into the "wild blue yonder" of Python programming, to get more experience using with statements and context managers. Of course, I'm not saying to abandon the book after the eighth chapter, but I am saying that you should be a fairly competent Python programmer at that point. The rest of the book's content tends toward specialty topics. An example of a "specialty topic" is Chapter 12, which presents the Python Regular Expression language and, to get a preview of what this chapter contains, you can visit InformIT.com and read the chapter excerpt for free. Definitely a plus if you want to get more of an idea of what the book contains before committing to spending your hard earned green buying this text. A few caveats. I run Ubuntu Hardy Heron and had a heck of a time trying to figure out the correct repository to add to /etc/apt/sources.list. I finally took the advice I found at this blog, though I much prefer letting the apt system manage my software. The Intrepid Ibex's repos have Python 3 already, so If you're an Ibex user, you're all set. I mention this only because the book isn't going to be able to give you every possible method of installing Python 3 for all conceivable operating system platforms and their versions. Believe me, I worked Google to the bone before going with an installation option that didn't start out with sudo apt-get install. The other important thing to note is that, if you have programs running on your computer or server using earlier versions of Python, don't make Python 3 the default. You'll want to run both versions of Python side-by-side to avoid breaking anything (that is, unless you don't mind rewriting everything in Python 3). If you're the proud owner of this book, comment back here on my blog and let me know what you think. Update: If you want Python 3 on Ubuntu Heron, you'll have to install it via the link I posted in the review. Only the Ibex repositories will have it available. Looks like it's time for me to upgrade.

5 comments:

  1. Im a new programmer and I thought this book looked cool, because I already have python 2(dont, or didnt use it at all though). And I have to say, a few days(3 to be exact) into the book, and im already loving it! Sure, there are some parts where I dont know what the hell is going on, but I am glad I got this book. This is a good book for beginners. (I was afraid to get the C++ guide)

    ReplyDelete
  2. I just purchased the book the other day, and while I am enjoying it, for some reason I cant find where they hid all the answers for the exercises at the end of the chapter.

    ReplyDelete
  3. I'm working thru the book at the moment. Like you I like it because it has exercises - I wish more books would include them.

    ReplyDelete
  4. To MeepZero: I think you're missing the point regarding the exercises at the end of each chapter. You see, you're supposed to work out each exercise for yourself, which forces you to actually use (and thereby learn) the language and its standard library. If you were given all the solution code, what would be the point of doing the exercises?

    ReplyDelete
  5. Actually, all the examples and exercise solutions are available from http://www.qtrac.eu/py3book.html

    ReplyDelete

Please make comments.