Python – One Month Later
So I've been writing in Python as part of my job for a month now... I am still writing using a text editor and running stuff on the command line (after dabbling in Eclipse and other Python editors). I can see why people like Python so much, it has some cool stuff.
What I discovered this week was the Queue object in Python. It is a thread-safe FIFO queue and it is there and ready to use. In C++ I would probably have found the definitive implementation through some library (hopefully in Boost) or I would have to roll my own with all the headaches involved in making sure just the building blocks work correctly. I'm not using it in the way that most people would expect but that is the great part of supplying solidly tested building blocks.
As usual the code I am writing needed unit-testing to make sure it did what it says on the tin. This meant a multi-threaded unit-test - I know this is a bad thing sometimes. I had to thrash it with the mountain of threads but the tests seem to work consistently (although I imagine it could turn up to bite me in the future). I am sure three-quarters of the code I have been writing are unit tests.
Some other great parts of Python I found is the function is a first class object, and I've even played a little with lambdas. I'm looking forward to investigating where the best place is to put the boundaries between C++ and Python code.
At the moment I am really at the tip of the iceberg stage, there is the 75% that isn't so obviously on display.
August 22nd, 2008 - 08:56
You mention C++ to Python boundaries. Have you checked out the Boost python libraries? They make the boundaries easy.
August 22nd, 2008 - 09:06
Hi Jon, how’s it going?
Oh yeah, I’ve used Boost.Python in the past (and think it’s really good – especially because object ownership is more or less explicit). It is just it is the responisibility of the developer to work out how much logic goes into each part. I am left wondering how much the functions should wrap – should they expose the lower level functions or should it export some functions with a bit of meaning. It’s not like I am going to have to make that kind of decision soon, but I am wondering about how much backwards and forwards over that bridge effects the performance.
SWIG is a bit of a beast in comparison as well, which doesn’t make it much easier.