python vs java



python


python vs java


A KEY DIFFERENCE: DUCK TYPING

The biggest difference between the two languages is that Java is a statically typed and Python is a 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 particular object instances in the program. For example, I might have two types Person and Car that both support operation "run", but Car also supports "refuel". So long as my program only calls "run" on objects, it doesn't 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's a duck".
This makes Python very easy to write and not too bad to read, but difficult to analyze. Static type inference in Python is a known hard problem. The lack of type information in function signatures combined with support for operator overloading and just-in-time loading of modules at runtime means that the most common type inference algorithms have nothing to work with until the point in the program's execution when the types are known anyway. The Hindley-Milner algorithm that is commonly used in functional languages like Haskell and ML depends on being able to know, for example, that certain operations are restricted to particular types. These languages also typically have function signatures that "seed" the algorithm with the type information for their arguments.
In Python, names have no strong binding to their type, and thanks to duck typing, function arguments can be used to pass in any object whose interface supports the operations required by the function. There is no reasonable way to determine the type of an argument in this case, which can be very powerful and convenient, and is a lot like how we use objects in the real world. In the real world I don't generally care if I have a rock or a hammer: both have "hit()" interfaces that result in similar consequences when called.
Classes in object-oriented languages are meant to model concepts, but concepts are purely mental constructs that are essentially attitudes toward the concrete stuff of reality. Duck typing reflects this fact nicely. An object doesn't have to "be" a particular type, it just has to be useable where a thing of that type might be useable. This can lead to surprises, but it's a more accurate reflection of the categorical fluidity of human thought than is the rigid hierarchy imposed by more restrictive type systems.
1. Python requires no "set up." A full python environment is already on every Linux machine, and on Macs. On Linux, the program yum, or the  yelow dog updater modified is written in python, so python is here to stay. Java requires a substantial amount of setup. So if you want to get started with python programming, just type python at the prompt. Now. That's it. To start with Java, call someone who knows it.
2. The systems written in Java that we have purchased all suffer from the need to have particular versions of Java installed, and thick clients of these systems also have that requirement. Support of Java appears to be expensive. We do not yet have a similar number of python systems, but no one is expecting configuration management to be an issue with them. From an educational standpoint, this sounds like a good way to become frustrated.
3. Python has its own idiosyncrasies. In Java, every object must be a representation of some class, but in python the "variables" are of a unique flavor. Variables do not represent objects [cf. object: something in memory that has an address] nor are they pointers, nor are they references. It is best to think of them as temporary "names" for an underlying reality, much like the allergy From a learning standpoint, this may be more difficult for those of us with 35 years of experience than it is for those first taking up programming.
4. A number of companies are stuck with a great deal of legacy code written in Python 2. Consequently, Python suffers from a misconception about how strict or loose the typing system may be, and how strictly it may be enforced. Keep in mind that because Python mainly works with "names" of objects, we are really not discussing the same thing when we discuss types of Python's objects that we are discussing in other languages. Python does offer some rather seamless type conversions that can make it seem that the concept of types is less strict than it is in fact. Learning Python 3 first makes sense, but most of the employment is still in Python 2.

No comments:

Post a Comment