Working with Python

February 2, 2010 by
Filed under: Development, Linux 

A while back I started pondering Python as a language, and mostly the fact that I haven’t really tried any of the newer and more modern languages around. Not to any great lengths at least. So, about a year or two ago I started fiddling with it, mostly just trying different scripts, writing some small hacks, and so forth.First, I wrote a Bluetooth scanner for bluez, then via Dbus interface and so forth. The ease this came with was completely amazing tbh.

Last few weeks I started writing some larger applications with python, to try and learn it a bit better. First of all, I’ve had large problems with all desktop recording tools I’ve found so far — they either don’t support GL/Direct rendering, or they simply crash, or colors are all flunked out, and so forth. So, simple idea was to use the tool I know that works — ffmpeg and xwininfo — and make an easy to use interface for it, a taskbar icon. Click it once, and get a cursor to choose which window to record, click it and recording starts (icon changes to a recording button), and click it again to stop it. There is a right click menu to make some preferences and to stop the recorder as well. It works, and it’s very very simple :-).

Second set of tools I decided to make is a set of API’s for the Eve Api. This is also nothing new, but it was a good way to get a handle on how Python works, and how the Eve Api works. On top of this I have written some very simple apps that downloads all marketorders and wallettransactions in game and displays them nicely in a console. It has built in support of all caching styles, downloading, login, local disk cache, and so forth, but so far has very limited support for the different API’s.

My main observation so far has been that I like Python for it’s hackability and ease of use. Stuff comes naturally once you get used to it, but the dynamic typing and hackability also comes at some price. First of all, it is very easy to create scenarios where the code will crash due to bad types in the dynamic type checking, and the hackability also means you need to be very wary of your architecture. Hacking away is almost never a good thing if you are preparing to undertake any larger projects imho, the risk of writing bad code is paramount, and testing bad code … well, it’s just worse 😉 . That said, I do like the language, it’s completely awesome, and someone else said not so long ago, you can get around the problems, you just have to test the code so much harder for it to be reliable. Personally, I wouldn’t use Python for a critical system/application, but for my day to day use, it’s not a problem, I can survive a crash every once in a while. Also, after getting used to the pydev plugin to eclipse, I just love the entire environment even more :-).

Comments

2 Comments on Working with Python

  1. Mikael on Thu, 4th Feb 2010 03:33
  2. Interesting thoughts, Oskar.

    Sad then that you don’t believe in large projects for Python, since I have a great idea in my mind (which I have to keep for myself for now). I was hoping you would participate — and the project I have in mind will become… very large.

    Well, we’ll see. I am hacking myself into Trac, or around, playing with plugins. Quite fun I would say, and I agree with your observations. Python seems very “hackable”, but it also seem very competent. But you are definitely right when your state that the loose (dynamic) typing can cause problems.

    Unit testing will be a major concern for all Python projects. Perhaps that’s why they’ve included a whole unit testing module?

    Best regards!

  3. Oskar Andreasson on Fri, 5th Feb 2010 10:00
  4. Mmm, maybe I am a tad skeptical, but it’s only opinion. My main problem with unittesting for languages like this, is that you need to test the entire binary. The dynamic typing means you will be in a lot of trouble if you accidentally return a class of one type but expect something else at some other point. Ie, you need to spend a lot of time either unittesting, or function testing on a very high level (which would come automatically with compiled languages).

    That said, the eve client is written in python. I haven’t even looked at the unit testing framework and how to use it in python yet =)

Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

You must be logged in to post a comment.