Core Python has been a very appropriate book for me. I was already a little familiar with Python. However, I am a long time programmer and know many other languages. I think I am definitely part of the target demographic for the book. As such, the "core" of Core Python was also the most interesting and relevant, especially functional
and object oriented programming
in Python. The last several chapters of the book are more a laundry list of things you can do in Python and how-to do them. This is interesting too, but probably more useful for a Python developer in the trenches. Still I found several nuggets in there worth talking about:
Threads -- This was by far the most interesting thing for me to read. Multi-threaded programming is hard. Python doesn't seem to try and get around this. It give you the basic ingredients. It was predictable but pleasing to see that functions can be passed in as arguments to a thread. One thing that disturbed me was the Global Interpreter Lock and this statement from the book "although multiple threads may be running with the Python interpreter, only one thread is being executed by the interpreter at any given time." That sounds like Python is actually essentially single threaded!
I did some experimentation on my Macbook, a dual core machine. Here is what a single threaded process looks like:
Here is what a multi-threaded program looked like:
Notice how both cores are in heavy use, but not 100% per core.. Not sure how to interpret this. What is interesting is that periodically I would see something like this:
The program is clearly single threaded at this point in time. This is what I would expect with two threads having contention over a lock, like say the GIL. Anyways, all this talk of threads has me psyched to read Java Concurrency in Practice, but that is another series of blog posts.
Database -- The surprising thing was cursors! At first I thought that Python forced some kind of stored procedure style of programming, then I realize that a Python cursor was just like a ResultSet
in Java (for example.) I was pleased to see the SQLite3 support in Python. I have experience with this in Ruby as it makes for a useful prototyping DB for Rails.
Web Clients -- The presence of HTTP servers in Python is cool. No, it is very cool. I thought this was a cool feature of Google App Engine, but now I realize it is just inherent with Python.
Web Services & Jython -- These are both covered in the 'Misc' chapter in the book. This was without a doubt the most (only?) disappointing thing in the book. The book would really be better off with this last chapter removed completely. Both topics are covered in very little detail. There was no mention of performance benefits in Jython ... which makes me wonder if there are any! This is the main reason for using JRuby over Ruby, and it would seem like a benefit for Jython. I will have to do some experimenting.
That's it! Now, as mentioned earlier, it's time to get back to Java and Java Concurrency in Practice.