6 ms·
Why not transpile python to JS instead of running an interpreter?
by adsharma 5y ago
Why not transpile python to JS instead of running an interpreter?
- Daegalus 5y agoBecause many want JS to die in a giant hellfire and then shat on the ashes. So alternatives are being made that don't rely on it.
- adsharma 5y agoIs dart your preferred alternative?
- amitport 5y agoThe parent is talking about transpiling python to JS. I don't see why people who hate JS would like python. The language itself is not any better IMO (excluding ecosystem here). edit: following some comments I want to add that the situation is symmetric IMO. I don't see the point in transpiling any of the two to the other.
- egeozcan 5y agoIt's just what you are used to. I dislike Python, I hate PHP, but I really like JS. I've seen people like PHP and hate Python too. You see more JS hate because it's a more common scenario that people happy with PHP/Python/Whatever would be exposed to JS later, than the other way around. You see a bit more Python hate lately because ML is all the rage and Python is to ML what JS is to the web. All mentioned languages having some weird backwards compatibility quirks doesn't help either. I find it good that people are trying to port their favorite languages, although personally I'd stay on the happy path for the target platform. Especially the browser, as it already has weird APIs, JS or not.
- amitport 5y agoI agree, I was fluent in JS and other languages before learning python and hated it for a while. Eventually, you get used to the bad parts of any language so they become mostly transparent (and every language has bad parts). Specifically, now that I'm very much OK with both python and JS I find transpiling one to the other kind of pointless in terms of any language property (can make sense in terms of ecosystem).
- adsharma 5y agoAggressive type coercions in js frequently comes up 16 == [16] true in js false in python
- egeozcan 5y ago>>> a = 5 >>> b = 5 >>> a is b True >>> a = -4 >>> b = -4 >>> a is b True >>> a = 300 >>> b = 300 >>> a is b False Every language has these, JS a bit more (because mostly impossible to fix thanks to backward compatibility). I don't understand why you would do that anyway. Most linters would display errors even if you did (in both languages).
- adsharma 5y agoGreat. Thank you. I'll remove the "is" operator from the supported subset and perhaps rewrite the commonly used "a is None" to idiomatic code in the target language.
- h8hawk 5y agoYou should always use 'is' with None. == Is operator that can be overloaded and 'is' is object identity comparison. It make sense when you understand object system. You will be terribly messed up when use some numpy array == None.
- el_oni 5y agoa==b would be true. The is operator is not the same as the equality operator The is operator checks to see if both point to the same area in memory. Small numbers are preallocated in python so they point to the same memory. >>>a=300 >>>b=a >>>a is b True
- amitport 5y agoOf course there is some internal logic. The point was that both languages have pitfalls.
- globular-toast 5y agoPython is loads better than JS. I have experience with both.
- deleted 5y ago[deleted]
- neolog 5y agoThat's https://github.com/QQuick/Transcrypt https://github.com/QQuick/Transcrypt
- adsharma 5y agoI'm looking into a python -> dart -> js approach. Emphasis on static type checking and small feature set that's easy to understand. https://github.com/adsharma/py2many/ https://github.com/adsharma/py2many/ Made a new release earlier today: https://adsharma.github.io/py2many0.2.1/ https://adsharma.github.io/py2many0.2.1/
- rtpg 5y agoPython's object semantics are extremely different from JS. There might be _some_ ways of emulating them with JS thanks to Proxy objects nowadays, but you're looking at a pretty big uphill battle I think.
- adsharma 5y agopython has a lot of features. But people use a small subset of it. So instead of supporting all of python, why not stick to the small subset that people actually want to use to solve a problem?
- ptx 5y agoDifferent Python programs use different subsets, so as you work towards supporting more programs the union of the subsets becomes essentially the full set, I would assume.
- adsharma 5y agoThe distribution of popularity of the features is not uniform. My intention is to carefully look at the intersection of relatively less used features and features that make python slow/inefficient and exclude them from the supported subset.
- mjburgess 5y agoare you sure? can you give an example? personally, i think pythons object model is extremely similar to js -- down to python essentially having prototypal inheritance
- chc 5y agoI don't think you have that quite right. Objects don't inherit from other objects in Python — you can't do `class Foo(object())`, for example. Python has class-based inheritance.
- 5y ago
- rthz 5y agoBecause a large part the Python ecosystem uses packages (and stdlib modules) with C extensions and you can't easily transpile those. The end goal of Pyodide is to be able run existing projects mostly without modification in the browser, and that is not possible if one doesn't support Python C extensions. (I'm one of the maintainers)
- saynotobloat 5y agoCan pyodide be run on in a server environment? If there is a wasm runtime on the server. Sorry my knowledge in this is limited.