Saturday, February 28, 2009

Python is slowly winning me over

I've been learning Python at work and I have to admit that it's slowly winning me over.

I was skeptical at first. I've been a low level programmer (firmware, diagnostics, operating systems, device drivers, etc) for most of my lengthy career. A mixture of C and assembly language has served me well for most of that time with a little shell scripting thrown in for good measure.

When I started my current job, I discovered they use a mixture of C and Python. The parts of the product which aren't performance sensitive such as the GUI are implemented in Python. This code is much smaller than C code to accomplish the same purpose would be. Thanks to the interactive nature of Python it's also much quicker to develop this code and to get instant feedback.

What finally won me over was examining a short script designed to generate some proprietary TCP/IP packets. This script had a small problem when talking to one of our products. It produced the integer and float portions of the structure with the wrong endianness. A little searching with Google showed me that adding a single "<" character to the format string used by the "struct" module (which prepares individual fields within a structure) would correct the problem.

It took a minute for the full impact of that to sink in to my deeply ingrained C mindset. A single character would correct my problem. Couple that with the fact that the script to generate these packets was probably less than a third of the length of a comparable C program and I was forced to admit that Python is much more useful than I originally thought.

I was tempted to end with a comment about old dogs learning new tricks but I suspect that phrase is far too tired to carry the proper impact. I am finding that old engineers can learn new tools with sufficient incentive. Seeing how much more productive I could be with solid Python experience under my belt is more than enough incentive.

No comments: