Use PyObjC to code Python under the Mac Cocoa framework, and MySQLdb to interface with MySQL! That’s the advice I got in reply to my recent blog. The discussions were so inspiring that I spent all time when out running yesterday daydreaming about how wonderful it will be to rediscover the aesthetics of programming and regain the control over my personal IT.
So, to recap a bit of my thinking: Once a programmer, always a programmer. If you’ve learned how to code and to master your own IT life to a certain degree, you get used to it. At least I did. But then fate wrote a declaration of incapacity for me. Not only did I become a manager and got to do less and less coding. More aggravatingly, I changed operating systems. Gone are the days when I could solve a task requiring simple programming in FOCUS, Visual Basic or Delphi. This is not because of rust (if you know how to bike, you can still do it even after long breaks), but because I can’t run my familiar tools on my Mac. And as for Java, PHP and Perl, I never learned them nearly as well, nor are they languages with which I presumed to want to control specifically the Mac environment, with which I expect to stay for a while.
Hence, I wrote my blog “Developing small Mac apps with MySQL” yesterday. And I’m very grateful for the inspiration provided by my Sun/MySQL colleagues on the Sun/MySQL internal discussion forum — thank you! The reply that ignited my feelings the most was by Mark Leith of the MySQL Support Team. He suggested me to go for MyObjC, as a way to combine Python, Cocoa (the prime Mac OS X software framework) and MySQL. And of course, I googled and read up on the topic.
This is why Python and PyObjC feels like the right choice for me to rediscover programming:
- Full control of Cocoa. PyObjC isn’t overprotective; there isn’t a limit after which I can’t go further. It’s as native as it gets on Mac, unless I’d program directly in Objective C. While interpretive when coding (a plus), it can be compiled for the standalone app (another plus).
- Good MySQL integration. Python is one of the Ps in LAMP. And googling for “PyObjC MySQL” gave 51000 hits.
- Proper aura. Python sounds modern and cool. Casually mentioning “a program that I just wrote in Python” would impress my colleagues born in the 1960s; coding comfortably in Cocoa would make myself feel younger.
So, Python and PyObjC it is. The next question is how to interface with MySQL.
- MySQL Connector/Python. When Geert Vanderkelen, also of the MySQL Support Team, put in his general pitch for Python, he mentioned that MySQL Connector/Python (myconnpy) is on the rise. Geert is the main contributor to myconnpy. However, going to https://launchpad.net/myconnpy I learned it’s still early alpha.
- SMySQL framework. When googling for “Cocoa” and “MySQL”, I hit upon http://mysql-cocoa.sourceforge.net/ which seems to be the fundament for some apps. There seemed to be several versions of it, I found out when stumbling upon http://www.sequelpro.com/cocoamysql.html.
- MySQLdb. Googling seemed to indicate that http://mysql-python.sourceforge.net/MySQLdb.html would be the right way to run MySQL not just from Python in general, but also from MyObjC in the Cocoa environment. Stating that my priorities are the MySQL classic value trio of Stability, Performance and Ease of use, Mark Leith confirmed that I was on track.
This means I’m ready to start. But I’ve been a sufficiently long time away from coding that I want to be a tad more systematic and goal oriented than just hacking around in general. Besides, I couldn’t just sit down, open my favourite editor and start writing, even if I wanted. I don’t know the Python syntax. And perhaps I could benefit from the added perspective of ten years without coding but instead with lots of management, networking and communication?
So here’s how I plan to proceed gaining familiarity with PyObjC:
- Books. That’s how I learned most other computer languages. Georgi ‘Joro’ Kodinov,
manager of the MySQL Server Team, recommended “Cocoa Programming for Mac OS X” by Aaron Hillegass and in Mark Leith’s link to the Apple Developer Connection, the page “Using PyObjC for Developing Cocoa Applications with Python” recommended O’Reilly’s Learning Python, Second Edition which I borrowed yesterday in German from my local library Gasteig here in Munich. There are plenty of other books, but those are the two I plan to concentrate on. - Training. Learning by doing was the method I used successfully so far, so I won’t change that. What I will change, though, is going about it in a more systematic fashion, which is why I’ve identified my learning goals below.
- Itches. The programming projects I want to write and use are the driving force behind all of this, and I have a pent-up demand for Regaining Control of my IT life. I’ve also documented those very pet projects below.
- Mentor. I’d love to find a Python mentor who can get me over the hurdles quicker. Some types of patience grow with age, other types diminish. And the “let me try the umpteenth way of reinventing a wheel that I’m sure is out there” type of patience has diminished a lot from my teens, when it really was about personally discovering the world of coding. Ideally, I’d find a Python mentor in physical vicinity here in Munich, probably half my age. Yes, I’d return the mentoring favour in some wake of life where I’ve got more experience. Hmm, next Thursday there’s a user group mtg in the local university LMU. Let’s see if I can make it!
- Sharing. As I progress and learn, I need to document what I learn in order to keep on track and not let me be distracted. That’s what experience has taught me. And working with open source, I’ve learned that great things come out of sharing, so I might as well blog what I document. If I’m as successful as in my wishful thinking, I’ll put my pet projects up on sourceforge in the years to come.
- Web resources. Documenting the web resources involved in learning PyObjC could be seen as a subgoal of the sharing goal, but it’s a big one. What to download and where, pointers to documents, tutorials, add-ons, forums and google groups is important enough to receive both attention and documentation.
The driving force is this set of pet projects, my itches that I want to scratch:
- kajtajm. Time tracking (date, from-time, to-time, project, freeform explanation about 40 chars) with productive grid input. That was the trigger for me to write yesterday’s blog and it was also the one I was referring to in the “Three key requirements”, “Input Screen” and “Output Screen” sections.
- kajbook. Bookkeeping, for personal expenses, for small self-owned companies, for projects. I wrote an ancestor in FOCUS (so I have fairly clear specs in my head) but haven’t been able to use it for years, for lack of a PC/DOS (or VAX/VMS or VM/CMS) command prompt.
- kajmejl. Email archive app for all my emails sent and received since sometimes in the last century, when I started using email. Parse the files from various generations of email (pine, eudora et al.) into a MySQL database. Index it to make it searchable. Free space by deleting the biggest attachments. Enable tagging and/or searching on people, projects, customers (which tend to change names over time, as centuries pass by). Enable pretty-printing of individual emails, and of forwarding them to Google Mail.
- kajdisk. Order is a key goal for me for 2010, and I despice retaining old CDs, DVDs and harddisks just because they might contain files that I don’t have any other backup of. So kajdisk loads the directories of the main backup drive into a MySQL database, and then checks whether individual CDs/DVDs/HDs contain any additional files. The app lists them and the user can then copy them (if they’re small and/or necessary) or choose to disregard them (if they’re unimportant) in order to immediately be able to throw them away. I expect to gain free physical shelf space from using kajdisk.
Finally, my Python / PyObjC learning goals. These are the steps in which I plan to progress.
- Hellöu wörld. Reading a text (in ISO Latin-1, hence the döts above the ö) from a MySQL database and writing it correctly onto a Cocoa screen. Requires installation at least of MyObjC and MySQLdb, and learning how to communicate between MySQL and Python.
- Basic language constructs. Loops. Declaring variables. Classes. The bare necessities (I plan to learn more while scratching the itches).
- MySQLdb. Understanding key components of the Python / MySQL database interface: SELECT, UPDATE, INSERT, DELETE. Navigating answer sets.
- Basic Cocoa UI elements. This I expect to be a lot like Visual Basic and Delphi, with a slightly different way to do binding between objects and the UI.
- Mathematical functions. Python seemed to know how to do a sum of an array natively, almost like APL. This is promising, perhaps there’s more fun to learn.
- An input grid. This worries me. Grids (matrix tables) were always a cause of concern when I coded in various versions of Visual Basic and Delphi. Often, they lack capabilities. Often, they let you change irrelevant attributes, but not the relevant ones. Often, trivial things require lots of workarounds. Let’s see about grid usability, both from a user and a coder perspective. Hmm, I suspect finding the right UI element to use will be the first hurdle.
- File system. How do I loop through the file system and retrieve all file attributes? Can I perhaps retrieve (or even write) EXIF attributes of JPG files? That would surely be a bonus.
- Regular expressions. I know how to grep and find, roughly, but I’ve always had to ask Giuseppe Maxia (and earlier David Axmark) for help on regular expressions. I suspect parsing through texts would benefit a lot if I learned regexps properly. But learning this isn’t a prerequisite for at least kajtajm, kajbook and kajdisk. Sure, kajmejl may require regexp knowledge.
- Clipboard, file export, PDF output. Those are things that aren’t requirements for the initial use of any of my pet project apps, but they clearly could help.
That’s it! I’m looking forward to experience my rebirth as a programmer during the course of 2010.
Links:
- Python: Wikipedia http://en.wikipedia.org/wiki/Python_(programming_language) Website http://www.python.org/
- PyObjC: SourceForge http://pyobjc.sourceforge.net/ Apple http://developer.apple.com/cocoa/pyobjc.html
- MySQLdb: Sourceforge http://mysql-python.sourceforge.net/ Documentation http://mysql-python.sourceforge.net/MySQLdb.html#mysqldb
PlanetMySQL Voting: Vote UP / Vote DOWN