Note: I have been meaning to get this post up for a while now. However since I am swamped with work in general, everything is delayed and taking longer than expected. Sorry about that.
As I mentioned in an early post, I am working on building up my professional experience in Python. It has been a few months–time sure does fly when you are busy as heck–so it makes sense for me to update you on my experiences with Python so far.
Living in Large in Python-landia
I always enjoyed writing Python scripts. Nothing quite beats Python when you need to write a script to search-and-destroy empty files or automatically converting files. Sure you can suffer through BASH scripting or BATCH for the poor souls stuck in Windows. You could write a one-liner Perl script that you could never ever read again. Or you could bring in a 800 pound gorilla into the mess by coding a full-on program in Java or C++. But why would you want to, if you can write a fully functional script in Python?
Writing scripts is one thing and writing applications is another. An full application contains a lot of complexity, structure and code, and initially I felt uncomfortable building a large web application in Python. Turns out it is not as big of a deal as I thought. First of all a lot of the code that I write in Java is boilerplate or object manipulation or setter/getter fetish. All of that goes away in Python. Also it is easy to simply use other people’s libraries for much of that other work, so the size of a Python application is considerably smaller. With a bit of careful organization and good code modularization, most of the problems go away by itself.
I found the last sections of Learning Python the Hard Way by Zed A. Shaw, an excellent reference as a both a refresher in Python and working with complex Python applications. Incidentally I found the book so good, I think I will use it as a textbook when teaching programming.
As I use Python more and more, the more I like it the way it is. Yes, I even have gotten over the whole whitespaces and tabs issue that most people get hung up about in Python. Besides the brevity and elegance of the language, how can you not like a language that:
- Has a Zen statement built into it. (Hint: run
import thisin a Python shell.)
- Refuses requests to be anything that it isn’t. (Hint: run
from __future__ import braces)
- Links to a xkcd comic about Python! (Hint: run
Using PIP and PyPi (Or Shopping at The Cheeseshop)
One of the fun things I recently discovered in Java with Maven, Ivy and Gradle was the concept of automatically downloading and installation of dependencies. I loved it that you could list the types of libraries that you’re application and everything automatically installed during the first build. Also having lived with Linux package management, I got used installing all my software via a package manager. Unfortunately many of the packages in Ubuntu are not the latest and greatest libraries that I need. Also building a Debian deb or RPM is an exercise in yak shaving.
Fortunately all those issues are addressed in Python. For package management you have the PIP utility, that installs packages available in a large web repository of Python libraries and applications called PyPi [http://pypi.python.org/]. This combination lets you install packages with a simple <code>sudo pip install $AWESOME_PYTHON_PACKAGE</code>. Pretty nifty, eh?
If you are wondering about the reference to “The Cheeseshop”. Apparently PyPi (not to confuse with the Python implementation of Python called PyPy) used to be called “The Cheeseshop” in reference to the Monty Python sketch by the same title. Fortunately finding software that you want in PyPi is much easier than shopping for cheese at the Cheeseshop.
Charming Code with PyCharm and PyDev
Python code like I mentioned is one of those rare languages where you do not need an IDE to use, outside of a text editor and a shell/console. I could not imagine doing the same with Java or C++. For anything more complicated than a small function you really do need a full-blown IDE like Eclipse. However after working with my favourite text editors Kate and Vim, I realized that I was missing better text highlighting and tab completion when writing Python code. A good IDE really does help and not hinder when hacking in Python too.
Being familiar with Eclipse, I started using PyDev, a great Eclipse plug-in for Python with Django and Google App Engine support. I highly recommend it, if you already use and are familiar with Eclipse. However even when using the Eclipse plugins for Git and Syntax colour themes, I found that Python on Eclipse is still sort of a second class citizen compared to Java. (Not sure if PHP or C++ developers on Eclipse have it any better in that case though.)
I experimented with quite a few different IDEs, while each offered something nice none of them really stood out. Then I met the nicest Python IDE out there: PyCharm. Of all the IDEs I’ve looked at PyCharm has the nicest tools, themes and feels much nicer than any other IDE out there. Yes, I know that PyCharm is proprietary and that I am breaking my own rules about using libre software. However there isn’t any IDE high quality enough that does what PyCharm does, including refactor, style checking and really good Django support. The Git support could be nicer, but for any complex Git operation I end up using a console anyways. Still I was impressed enough with PyCharm, that I actually bought a license for myself pretty much on the spot.
Other IDEs I’ve looked at included:
- Wingsware IDE: proprietary but seems like a decent competitor to PyCharm
- SPE (Stani’s Python Editor) : Seems pretty like a pretty decent IDE with support for Blender Python scripting.
- eric: A nice, classic IDE that I’ve used a few years back.
- Monkey Studio: A great alternative to Qt Creator and has decent PySide support.
- SciPy: An IDE for scientists and engineers using Python.
Dancing to the Sound of Django
While working with Python is pretty sweet, for me the big question is whether or not I can potentially make a living using Python. Since most of my expertise is in web or web-powered mobile applications, I was most interested in what Python can do in that area. Hence my interest in Django.
After using Django for a while, I can confirm that it is an amazing framework. Django has captured my imagination of what can be done with Python. While it takes some time to get used to the framework, it makes building web applications easy and enjoyable. A lot of the tedious and mundane work like building administrative forms, mapping models to database tables and input validation, are dealt with for you. Django is very modular, so with a bit of effort various underlying technologies can be swapped in and out. Django provides smart defaults, but allows you to easily override the parts that don’t make sense. One example is that it is fairly easy to override the default ORM SQL that is auto-generated from a model, to match the model or database better.
Documentation can make or break one’s perception of a library or framework. Django has awesome documentation, and so do many of the community-contributed apps and systems of Django. Some the add-on components really add a lot like Taggit and South, which provide tagging and database migration to Django. Also there are some great books on Django:
One of the best parts of Django that I’ve encountered is the community of Django developers. Unlike some communities, Django seems to get developers who are knowledgeable, friendly and approachable. By hanging out on the #django IRC channel and asking the right questions, the devs there were able to help me out and answer some of my questions faster than I could of possibly been able to find the answers myself. Of course as with any open source project community, you need to ask smart questions. There are also local Django groups. In fact I am looking forward to going to my first Django Toronto meetup.
Django is a really cool web framework for Python. The designers of Django, really put a lot of effort in making a great framework. The documentation is top notch. The community is amazing. To top it all, it is named after an amazing and cool French-Belgian jazz guitarist Django Reinhardt. If you are into jazz or swing music I highly recommend checking out his music.