Monday, July 9, 2012

Why People Choose Java over Python



I love Python for the freedom it gives to a developer, and for the way it allows one to concentrate purely on the business logic part of the solution, rather than on the nitty-gritties of the language. Coming over from C/C++ world, it's a breath of fresh air, no matter how much you love C/C++.

Despite all this coolness, this awesomeness of Python, and this black-magic-like problem solving ability that it offers, it's heart-breaking to see the adaptability of this superb language staying much lower than it deserves to be. The industry is still banking on Java for addressing its requirements.

Over some time recently, I have been trying to understand what makes people prefer Java over Python for new development, despite Python being such an excellent choice.

So from whatever little I have understood about the technological landscape so far, here are some points (without any priority as such) that I could put together, as to why java might still be a go-to rather than Python -
  • Java is compiled while Python is interpreted. When you want to deploy a webapp on a third-party web host, with Python you have to deploy all your source on the server, while in case of Java, you deploy compiled bytecode (classes and jars). And though bytecode reverse engineering may not be impossible or uncommon, it just makes access to source-code much more difficult, as compared to Python where you have to deploy production source-code as it is. People are paranoid about exposing their source code.

    CPython / Jython / IronPython might offset this shortcoming to a certain extent, but then this is an added layer, and it might come with its own set of drawbacks, limitations and bugs.

  • A Java webapp, when deployed under an app server like Tomcat, allows request pooling and hence will possibly be more responsive. For a WSGI/mod-python/FCGI hosted Python web-app on the other hand, all requests result in a new fresh invocation of the interpreter and it will be, I suspect, much slower in comparison with a request-pooled instance which can maintain its state.

  • The biggest thing, in my opinion, that goes in favor of java, is the huge ecosystem, of proven tools (development, debugging, profiling, build-management, documentation etc) and frameworks, that has been developed around it over the last decade or so. And 'proven' is really the keyword here.

  • When it comes to language constructs, Python doesnt enfoce anything. It's a come-all-do-all language where even following OOP paradigm is *voluntary*. for exmaple, encapsulation, which is a very important OOP building block, is not enforced. It's voluntary. You can use _underscores_ and __double_underscores__ if you will to specify class variable accesses, but then there is no restriction on their being accessed from outside the class definition - private/protected/public notwithstanding. So chances of a developer making a subtle but critical mistake are much more than say in java.

    Managers, product owners, and anybody for that matter, want to have the peace of mind that the software development process they are overlooking, will have stringent checks in place at the grass root level itself, so that a subtle mistake from an inexperienced developer wont go on wreaking havoc on production.

    Java to a large extent has those checks.Pointers, or rather lack of it, was one of the reasons why it gained acceptance above C++ after all. Java enforces OOP paradigms. It has static typing as opposed to duck-typing or dynamic-typing in Python. Due to enforcement of OOP, it opens up large possibilities for development methodologies, like interfaces and contracts, which, though possible in Python, will be bypass-able, due to its weak OOP support.

Again, to reiterate, I have jotted this down as per my understanding of the technological landscape. I am nowhere near being an expert in either Java or Python, and I do not claim to be one either. So there might be some errors in the way I perceive these things, and if you spot one, please point it out.

With that, I open it up to you guys. I am sure there will be lots of viewpoints as to why Java clicks, since we have such a large experienced Java population here. And there will be counter-points as to why Python clicks despite these points or why some of these points I mentioned aren't valid anymore. So let those viewpoints flow.

1 comment:

Shardul said...

Very first point point blank.
I often get to hear arguments like - "but why would I deploy all my logic in understandable text" ?