Hacker News new | ask | show | jobs
by btilly 5049 days ago
Ah yes, the age-old static typing vs duck typing argument.

Sure, in theory static typing can catch bugs. But doing it like Java does it is a lot of work per real bug actually caught.

1 comments

Whether or not that's true, it is a concrete difference between Python and Java. Python is not a superset of Java.
I never claimed that the two were the same language. My claim was that you can take anything written in Java and pretty much directly translate it to Python.

The fact that there are things Java will flag as errors that a Python translation does not, does not change this fact.

As I said, you seem to be claiming that Python is a superset of Java, not equivalent to it, and that claim is manifestly false. Errors that are detected in one place and not in another are a manifest difference.

Also, Java threads and anonymous classes do not translate directly to Python.

Python has threads.

In Python classes are first class objects, and you can easily do anything you could do with Java anonymous classes on the fly. Furthermore Java anonymous classes are usually used as a verbose replacement for a lack of closures. But in Python you can create closures and pass them around. (You do have to do some juggling to mutate variables, but 1 element arrays are only a slight pain to work with.)

Yes, but again, there is no Python syntax for anonymous classes. That you can "easily do" something a different way is not proof that two things are the same, it's proof that they are in fact different. Which again, is my point. That Python has other, different features that can be used for other different effects just makes it that much more different.

Python has green threads, but if you want concurrency, you have to resort to the process module. This is not a limitation Java's threading shares.

I'm not arguing that Python is bad or inadequate, just that it is a fundamentally different thing and should not be viewed as a superset of Java.

I'm not saying you should do this, but you can have an anonymous class like this:

  type('', (dict,), {'__init__': lambda self, *args, **kwargs: not super(self.__class__,self).__init__(*args, **kwargs) and setattr(self,'__dict__',self)})
Python easily allows multiple threads to exist at once. The only reason they don't run at the same time is an implementation detail of the most common Python implementation. Python running on the CLR, the JVM, and extensions for both CPython and PyPy show that you can run multiple threads concurrently if you really want to.
My claim is that it is fairly easy to translate any Java program into an equivalent Python one. That some things need different constructs is not evidence against this claim.