The latest release of
IDAPython 0.8.0 gave me an incentive to look into the wonderful world of Python for the first time. Equipped with
the Python tutorial from the official Python website and Google I decided to
port my InstructionCounter plugin to Python, just to find out how Python and IDAPython work.
Here are my first impressions of Python:
1. Despite liberal use of empty lines the Python version is only 48 lines long, compared to the ~150 lines of the C++ plugin. I see four main reasons for this: The C++ plugin has 11 #include directives. It's also necessary to define the plugin structure and some functions IDA expects in the C++ version. If you use IDAPython this is done for you as part of the IDAPython IDA plugin. The third major reason is the lack of lambda expressions in C++ (unless you use something like Boost::lambda). The last reason is that my C++ plugin supports two versions of IDA (4.8 and 4.9) using some kind of conditional compilation which also takes a few lines of code. The actual functional code is pretty much the same in C++ and in Python.
2. Python string formatting using the well-known printf placeholders in combination with the % operator is pretty cool.
3. Where is the ternary operator? Seriously. That's the main issue I'm having with Python so far.
4. I like the Python collections a lot.
5. I think the : behind if-statements or loops should be dropped. Maybe there's some deeper meaning behind it but so far I've only experienced it as syntax pollution.
6. Yay for aspects from functional programming (map, filter, reduce, ...).
7. IDAPython is pretty cool. A perfect intermediate step between IDC scripts and writing entire plugins. I don't think I'll ever write IDC scripts again.