Programming

Python Vs Java

 Python has a bunch to offer for Java developers, and the languages are interesting both in their shared features and differences. The biggest similarity is their “(almost) everything is an object” design and their reputation for excellent cross-platform support, as well as things like immutable strings and deep, relatively standard libraries. But they have their own differences too. That is what we are going to focus on today.


Python – Lets you get the job done

Python lets that happen, it is a language that gets out of the way and lets you get the job done. It often feels like it is a helpful assistant handing you tools. Need a tool to “download stuff” from the internet? Got that. Parse the results? Easy. Run a singular value decomposition on a sparse matrix? Anytime.


Used with the appropriate discipline and testing, Python can comfortably scale to massive applications and powerful web services. We know this because it has been done. It is also a great “glue” language for bringing together everything from Fortran-era numerical libs to statistical algorithms in R.


The biggest difference between Java and Python is the statically typed nature of Java verses Python, that is dynamically typed. Python is strongly but dynamically typed. This means names in code are bound to strongly typed objects at runtime. The only condition on the type of object a name refers to is that it supports the operations required for the exact object instances in the program.


For example, I could have two types of Person and Car that both support operation “run”, but Car also supports “refuel”. So long as my program only calls “run” on objects, it does not matter if they are Person or Car. This is called “duck typing” after the expression “if it walks like a duck and talks like a duck, it is a duck”.


Java – Type Information

The lack of type information is a common issue that Java developers find themselves running into if they are used to operating in a Java powered environment. This is because it can be hard to tell what is going on in any given place in the code, particularly when the names are ambiguous, which they often are.


Consider this extreme case, where you typed b.polish( ) in. Does that do some kind of fine-tuning on the object, or translate it into a well-known Eastern European language? Or something else? Even if this is an extreme example, you get the point. If “b” is ten layers down in a call stack it is going to take a long time to answer that question, and if the upper parts of that call stack branch out and are called from a variety of locations, any one of which could be passing in an object of a different type, you could be in trouble.


Java is statically typed. Names in Java are bound to types at compile time via explicit type declaration. This means many type errors would result in a runtime error and often a program crash in Python get caught at the compile time in Java. You can tell at a glance what type of object a name is associated with in Java. This clarity makes it easier to debug when you run into an issue. But it depends on the workflow you have setup.


To conclude, Python and Java both offer their pros and cons. Thanks to Pythons dynamically typed environment you can make a lot of headway with fewer details getting in your way. This is a big advantage if you want to throw together a prototype of a software quickly. But if you run into bugs because of the nature of how Python compiles you will struggle to easily find the root of the issue.