Sunday, February 1, 2009

Don't panic

It is said that despite its many glaring (and occasionally fatal) inaccuracies, the Hitchhiker's Guide to the Galaxy itself has outsold the Encyclopedia Galactica because it is slightly cheaper, and because it has the words "Don't Panic" in large, friendly letters on the cover.

A little while ago at the Cloud Connect, I got into a conversation with a fellow developer who was ramping up on building an App Engine application. Like me, he originally came from a Java+SQL background, and we had an interesting chat on how to convert some data modelling concepts onto the datastore in a performant fashion. At some point, he asked me the following question:
What are the top three pieces of advice that you would give a fellow Java developer when ramping up on App Engine with python?
The following is my response:

1: Don't panic (I actually said "don't be afraid", but that would be less of a catchy phrase for a blog post, wouldn't it? ;-)
2: Kiss your IDE goodbye
3: Write lots of unit tests

So, why did I pick those three?

Don't panic:
Learning a new framework takes always a certain rampup time in which one is less productive. Learning a new framework plus a new language can be even more frustrating. For a seasoned developer who has gone through this a couple of times, this is probably old news. However, as Java has been taught at colleges worldwide for a decade now, chances are that there is quite a segment of developers out there who started out with Java and never had the need to switch to anything else. Trying out something new can be difficult in the beginning, but it really is worth it. Even if web applications were to suddenly disappear, the knowledge I gained around python during the process would still prove extremely valuable in my job. It is a great tool to have around for many tasks that require to put something together quickly with little overhead.

Kiss your IDE goodbye:
For my development on App Engine, I use Eclipse with pydev. It serves many purposes like debugging or making the code easier to read through syntax highlighting. However, it seems to lack the one feature that I love most of all: code completion.

When I type code into my editor, I want the development environment to guess for me what I'd like to put in next. Say you work with a couple of languages (Java and Python) and have to jump back and forth. You are familiar enough with them to use them, but do not know exactly know all the common libraries by heart. So, assume you have a string variable foo and convert it to upper case. What's the method? foo.toUpper()? foo.upper()? foo.to_upper()? foo.upcase()?

Many languages have the same type of features, but there are subtle differences in how they are named. If one works very intensely with one language most of your days, these kind of things are no-brainers. However, if one always has to go to documentation to look up these small things, that
accumulates to a lot of time wasted. Good autocompletion reduces the time for lookups and the propability of typos in these cases. Now, I have been told that there are alternatives our there that have significantly improved capabilities, and I am really looking forward to giving those a try at some time. I would imagine that they would still be lightyears behind the tools I have for Java though, for a couple of simple reasons:
  • the Java tools have been around much longer, so there is some catching up to do
  • the python tools have a much harder job at "guessing" because of the way the language work: how should I guess method names on "foo" when I cannot extract the object's type out of its definition ("def bar(foo):")?
  • python does not get compiled, which means there are less "compiler warnings" that could get displayed to me -- less opportunity to make me aware of issues that might blow up in my face once I try to actually run the code.
Write lots of unit tests
Typos are my worst enemy in python, since my editor does not necessarily tell me about them. They hide in my code, patiently waiting for their five seconds of fame once the code gets executed. If the typo is in a branch that rarely runs (such as how to handle certain errors that do not happen often), a typo might stay in hibernation for a long time, until it annoys the heck out of my end users (it wouldn't be the first time that Finagle's law sneaks up on me). For that very reason, I urge everyone to test your code. Test it much and often. Write automatic unit tests (see my article from last year, or also this farily recent summary of several other posts on this subject). Develop a habit of writing code in small increments and adding unit tests immediately after (or, if you can manage to be even more thorough, try out test-driven development). By the way: this is also a great habit to develop in other languages, including Java. Make faulty code blow up on the local development box -- not in front of your customers!

In summary...
So, there you have it: my top three pieces of advice for newbies switching to App Engine. They are not perfect, but it's what I believe. What I would be interested in is: what would you have answered if you had been asked the same question? Please post your response to this thread...

2 comments:

SDC said...

While it's not an IDE, I really like Komodo Edit for my Python hacking needs. It does the code completion and syntax highlighting, and is relatively lightweight, which I also like.

Dom Derrien said...

Being more a JavaScript developer than a Java one (I really push as much as I can client side), I'm used to coding without much code completion...

I have been more disturbed by the way Python implements some concepts. That's why I spent a lot of time on Python Basics page (http://www.astro.ufl.edu/~warner/prog/python.html).

I think the key point is to rely on a build script that checks the code (with PyChecker, for example) and that run the test suites.

BTW, thanks for the reference on my post;)

A+, Dom