The colorful wolf

September 5, 2010

Java versus Python

Filed under: Tech — randy @ 23:55

I’ve been working a lot on a personal project recently, not for monetary gain, purely to solve a pet peeve of mine that I’ve had since a long time ago. I’ve always been slightly miffed that there is no single website available to me where I can maintain a list of all the things that I’ve seen (movies, tv shows, anime) or read (books), and what I thought of it. I gave up on this project last year because I found out about this website called Anime Planet, which almost completely fulfilled my needs in terms of anime. I was already using IMDB to keep track of movies and tv shows for me, but realized that both sites are still lacking for me. What I really want is a single list of all my things, regardless of what kind of thing they are, and I want to be able to rate the same thing multiple times, using different dates for each rating. That’s the core idea that I wanted to accomplish with my project.

I started this project last year on a vacation but never quite finished it. I got quite far to releasing it but then gave up on it for lack of time and the discovery of Anime Planet. Now that I’ve got time again I’ve picked it up, and I’m hoping to release it before I find a job, which will undoubtedly be disastrous for my free time. The nearly finished app was implemented completely in Java using Hibernate, and was very enterprise-y. I had a lot of cool ideas that I wanted to accomplish and started to work on already but left half-finished. Still, the back-end was fairly robust. The front end, though, was a bitch. I used the Prototype javascript library to AJAX my way in-between the client and the server but never really designed things right, making the whole thing a mess and bothersome to maintain. I needed something else.

Enter the wonderful world of weirdly-named six-letter frameworks: Joomla, Drupal, Django, Spring, Struts, Hadoop, whatever. There’s too many of them, and no, I did not consider Hadoop for my project, I just wanted to mention it here because it resonates nicely with the other silly names in the list. I mentioned in my previous post how disappointed I was at Spring, and looking at all the Java Facelets/Portlets/Server Faces stuff didn’t make my life any easier, so I decided to give up on my comfortable Java environment and try out something new instead. After a couple of days of researching the many unknown frameworks I decided on a Python-based framework called Django.

I should note here that I am seriously intent on putting this web app online at some point in the future, and my hoster won’t run Java on their servers, which helped me take the decision to plunge into Python. And what a plunge it was: it’s hard to describe how much simpler my life has become since I switched to Python+Django. There’s just so many things I don’t have to worry about any more. Getting started with Django has been a dream. The documentation is easy to understand and makes so much sense. The Eclipse plugin just installed and worked on the first try (*cough* unlike Spring *cough*). Following the instructions in the tutorial project is also straight-forward and everything just works the way it should (*cough* unlike Spring *cough*). I am still amazed at how little code I have to type to get something quite complicated to work. It’s the complete opposite of Java.

In one day I was able to develop the Python web app to do about 90% of everything that the Java app could ever do. I haven’t measured how many lines of code it took to do this, but I’m pretty sure that the Python version is less than half as big, partly thanks to the compact syntax of Python and partly thanks to the excellent libraries that Django provides. The code is a lot cleaner, both at the architectural level and inside each individual file. The only potential source of worries I’ve found so far is that Django doesn’t do connection pooling for MySQL unless you hack it a bit, but I’ll worry about that when/if I get there. I read somewhere that Python is exceptionally great if you don’t know where you’re going. I don’t know exactly what this web app is going to do when it’s finished, but I know that Django gives me the flexibility I need to try out all kinds of things.

I know that there’s probably other frameworks out there that could make my life even easier, but I already spent two days scrounging the net to find info, comparing frameworks, doing tutorials and trying them out on my pc. If I really wanted to choose the best framework for my needs I’d need to research another two weeks or even two months. At some point you just have to get productive, stop searching and take the best thing that springs (..) to mind at the moment. In my case that turned out to be Django.

When talking about productivity a lot of books and articles recommend that you create pressure on yourself by announcing your goals to others. When other people know about your goals you’ll feel extra pressure to not lose face with them, and you’ll push yourself harder to succeed. Being my usual skeptic self, my first thought is that this doesn’t apply to me because I don’t judge myself based on what other people think of me. But then again, I might start to feel pressure from this later on. Let’s see what happens. In any case, I’ll keep posting updates on my project as I go along. It might not be as exciting as cycling around Japan, but bear with me 😛

Later!

Advertisements

6 Comments »

  1. If you like Django, you also may like Play framework: http://www.playframework.org/

    Comment by Kęstutis — September 7, 2010 @ 8:50 | Reply

  2. It was great to read a post which verbalises the same experience I had a few years back on a personal project. As a Java/Spring developer I put together a web app for a local charity and chose Python/Django because the web host wouldn’t run Java (let alone Java’s memory requirements). I’ve never looked back since.

    This is an easy decision to make for a personal project but much more problematic when trying to convert a small Java/Spring team to Python/Django. This will prove much more difficult in terms of politics, time and expense. There is a trade-off between the obvious benefits you mention in your post versus the increased complexity and cost associated with increasing the number and variety of technologies used on a project, particularly with a large legacy Java/Spring codebase.

    While trying to quantify that trade-off, directing the team to posts like this is a good start!

    Comment by Safe Hammad — September 7, 2010 @ 12:00 | Reply

  3. About announcing goals.
    A short TED talk “Derek Sivers: Keep your goals to yourself”

    Comment by Meelis — September 7, 2010 @ 20:48 | Reply

  4. “no single website available to me where I can maintain a list of all the things that I’ve seen (movies, tv shows, anime) or read (books)”

    actually, such a website exists : http://www.senscritique.com … but it is only available in French so far, and officially launches tomorrow…

    Have fun with Django !

    Comment by Tibal — October 31, 2010 @ 9:24 | Reply

  5. You may also be interested in http://jython.org.

    If you haven’t seen it, it is a version of Python that runs on a JVM. You can use native Java classes, compile your Python to Java byte code, and use many popular Java frameworks. You can even use most of Django without modifying your code.

    It’s quite a fascinating project.

    Comment by Jerry — October 31, 2010 @ 15:16 | Reply

  6. I have faced similar issues, but my experiences have led in a somewhat different direction. I came to the conclusion that the problem with the bloat and inflexibility of many Java web applications is not actually a problem with Java itself, but instead a problem with the culture of the technologies used with it. Hibernate, Spring, Struts, tiles, jsp and so on seem to cause at least as many problems as they solve.

    With this in mind I wrote my own light-weight approach to web application development which (it turns out) has much more in common with the way web applications are typically written in the recent crop of dynamic languages. As with all such things the examples on the website are a bit out of date now, but a good flavour of what I was after can be seen at http://mojasef.stringtree.org/principles.html

    Admittedly, for deployments which can’t run Java (such as low-cost web hosting) I have been having fun with Ruby and Sinatra, but when it counts I am still more productive and equivalently concise using Java with help from Mojasef and Stringtree.

    Comment by Frank Carver — November 1, 2010 @ 15:11 | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: