3 ms·
I've been writing Python for maybe 3 months now and as I started digging into the OO stuff, I commented to a few developers about how it 'felt' a lot like javas
by 198d 15y ago
I've been writing Python for maybe 3 months now and as I started digging into the OO stuff, I commented to a few developers about how it 'felt' a lot like javascript and they nearly took my head off. Is there any material you (or anyone for that matter) can point me to that might help solidify my argument?
- tantalor 15y agoCan you elaborate? Honestly I think the differences far outweigh the similarities. One case that comes to mind is how each language implements (what I call) the continuation pattern. Suppose you want to iterate over the vertices of a binary tree. In JavaScript, you would accept a callback parameter which you call with each vertex. In Python, you would yield each vertex to the caller. These are very different styles and lead you in different directions.
- natedub 15y agoIan Bicking gave a talk on the similarities and differences between Python and Javascript that might be helpful, but it's pretty high level: http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-javascript-for-people-who-know-python-4900851 http://blip.tv/pycon-us-videos-2009-2010-2011/pycon-2011-jav... The key similarities in my mind are: 1) In both python and javascript, the class and prototype are exposed and can be called explicitly if desired: MyClass.method(my_instance, arg1, arg2) MyClass.prototype.method.call(my_instance, arg1, arg2); 2) Python will automatically bind methods when you retrive them from an instance. Unless you explicitly bind a function in JS, the "this" parameter is specified at call time: whatever comes before the dot is used as "this". Ultimately they're both first class objects and the difference to the developer is notation: bound_method = my_instance.method bound_method = my_instance.method.bind(my_instance); 3) Attribute lookups in Python behave very similarly to property lookups in Javascript. Python has a modified resolution order for searching for an attribute through its list of parent classes. Javascript will look for an attribute in a series of prototypes (since in JS, an instance's prototype is just an object, so it too can have a prototype). Python is superior here because it supports multiple inheritance, but overall the resolution behaviour is essentially the same. Can anyone think of any other common ground?
- deleted 15y ago[deleted]