Hacker News new | ask | show | jobs
by btilly 5049 days ago
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.)

1 comments

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.
Your claim is untrue, and that different constructs are needed is evidence. It is often easy, but that isn't guaranteed.