Hari's Corner

Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and then

Python and Java

Filed under: Software and Technology by Hari
Posted on Sat, Jul 30, 2005 at 16:42 IST (last updated: Wed, Jul 16, 2008 @ 20:43 IST)

I've been learning Python and Java and while it might appear as though I'm comparing apples and oranges, it's really interesting to note how different these two programming languages are. Not just in syntax and language structure, but more importantly in principle and programming approach.

At first sight, both Java and Python appear to be similar because they're both object-oriented, high level programming languages with quite a rich set of features. Both Java and Python code compiles into byte-code which is machine independent. Both languages typically provide a higher level of abstraction than, say C or C++ where you often get down into the nitty-gritty of things. However, amidst all these similarities Python and Java represent two different cultures in Object Oriented programming.

What makes Python and Java so different? Quite apart from the basic language structure and syntax there are several differences that I noticed while coding in Java and coding in Python. The whole thinking process as a programmer is different when you develop applications in these two languages.

Let me first take the case of Java. Java is a high-level language but actually provides an entire sub-system for the programmer. This can be daunting for a beginner who won't find it easy to get a grip of Java. Typically you must first learn Java and then go on to learn how to accomplish your tasks in Java. And because the whole Java API is a universe by itself, it demands a programmer to adapt to the system before he can do something useful. When you program in Java, you will spend a lot of time reading the documentation. In other words, you need to fit your programming task to the Java way, requiring more discipline and more planning to write programs that go beyond a few hundred lines. But this can be rewarding because Java forces this discipline on you and your program is naturally better organized in the long run. With Java, you actually get to think a lot more in terms of classes and objects.

In a nutshell, Java enforces a certain way of thinking and a certain structure in programming. This doesn't mean that you sacrifice freedom or power, just that you use that freedom and power the way Java lets you to.

Python? Well, Python's case is rather different. Essentially it is closer to being a super-powered scripting language than a programming language, but it combines so much power that it cannot rightly be called a mere scripting language by any means. However, one can notice the difference in principle and in actual practice. The philosophy behind Python is that it allows you to do more things with less code. Because of the enormous number of Python modules available providing such rich functionality off the shelf, this frees you to accomplish tasks using Python rather than forcing you to do it the Python way. Notice the difference in the emphasis. What does this mean? It means that as a programmer you can write powerful programs with more freedom and less code. Also Python, being an embeddable language can also be used as a scripting language within other applications. A language that is designed for easy accessibility and easy usage.

In short, Python allows you to think in terms of what you want to do without necessarily asking you to do it in any one way. Programmers would find Python closer in many ways to C/C++ than Java in its philosophy without the lower-level approach of either C or C++.

I'm deliberately refraining from saying which approach is better. Both these languages are great to learn and both are high-level OOP languages. But each requires a different mindset while learning. My take? Java is definitely suited for larger projects typically requiring more planning and a methodical approach. Python allows you to create powerful, non-trivial applications with less effort than either C or C++.

Which is better suited for any given task depends more on the mindset of the programmer.

No comments yet

There are no comments for this article yet.

Comments closed

The blog owner has closed further commenting on this entry.