Monday, November 17, 2003
yes yes yes

This is a very heartening bit of writing.

(found on this weblog, which I found on this page)

12:39:22 PM    comments ()  trackback []  

pyobjc adventures

I finally found the time to sit down with PyObjC this weekend. I'd poked around with it and looked at the examples before, but this was the first time I sat down with it and wrote some semi-substantial code.

I decided that the best thing to do would be to convert my (small) set of Objective-C / Cocoa projects to PyObjC and see if I could make them work the (or maybe even better). For the most part, the conversion went surprisingly easily, and I was able to make everything work as expected. In fact, because I was able to change the implementation language to Python on one project, I quickly took the code farther than I had expected.

It was no surprise that in a side-to-side comparison, with similar implementation algorithms, the Objective-C code ran much fast than the Python code. But when it came to extending the code and adding new useable features, the Python version won hands down. It could be argued that I more familiar with Python than I am with Objective-C / Cocoa, and that would certainly be true. But never underestimate the gains of not worrying about memory management.

I have some Python code that communicates on a serial port with some hardware. It is easy to understand and straight forward. In trying to write the same thing with Objective-C and Cocoa, it became a nightmare. It is amazing how quickly you forget about all of those allocation and buffer size issues you have to deal with when you are used to using Python (at this point, whenever I say "Python," please substitute "Any language with automatic memory management and a decent string library"). In this day when buffer overflows create security holes for script kiddies, why aren't we using tools and languages that help us prevent these mistakes in the first place? OpenBSD's code auditing is a fantastic thing, and I'm highly in favor of it. Wouldn't it be nice to reduce the necessity for it?

Back to the original intent of this post -- It was amazing to me how quickly I forgot that Python was not a native Cocoa speaker. Like many other people have said, it just works. Plus, you get to use Interface Builder to define your UI, and if you've never tried it, you are in for a treat. I love being able to wire up objects, and know that they really ARE objects, rather than some GUI-editor writing some source code behind the scenes.

It just works. It'll work so easily that you will start to giggle. I know I did.

9:28:00 AM    comments ()  trackback []