8 ms·
Jaspy – A Python VM written in JavaScript
- mrcactu5 11y agoare we limited to certain libraries for now? I am guessing we can't do pip install, but maybe this version of Python can interact with other javascrupt (e.g. JQuery)?
- koehlma 11y agoMost of the builtin types and functions are not fully implemented yet, but if they are, you may use any library that is implemented in pure Python. There is already support for threading and I am also planing to implement a filesystem as well as multiprocessing using WebWorkers. Even sockets will be possible with node.js. Then yes, you can do "pip install". There is also a module that allows you to use native JS libraries like JQuery.
- ruffrey 11y agoPeople often look at things like this like 'why would you...' But it is an interesting experiment that might make web programming more accessible. I think of my physicist cousin who uses python for data analysis. An option like this might lower the barrier to sharing data on the web - less JavaScript ecosystem knowledge required. JavaScript frontendy land moves so fast it can be overwhelming to outsiders, even if JavaScript itself is "easy."
- xaduha 11y agoYou need exactly zero knowledge of Javascript to share data on the web. Plain server generated HTML + some CSS framework is more than enough for most cases. Even if you want some more interactive stuff you don't need to know the "Javascript ecosystem". It's still possible to link a couple pf JS files in script tags, you know. It's even possible to link XSLT 1.0 stylesheet for some non-interactive clientside processing.
- magnumkarter 11y agoThis was my first reaction, but one of the examples allows dom manipulation. https://github.com/koehlma/jaspy/blob/master/example/hello.py https://github.com/koehlma/jaspy/blob/master/example/hello.p...
- gedrap 11y agoAs with everything, there are trade offs and in this case, I don't think they are worth it. What are the most common use cases for JS, that might be a barrier to an unfamiliar developer, requiring some learning? I believe that making an ajax request and some trivial DOM manipulation covers a lot (say, send ajax request to the server and add some text returned to a dom element). In order to do that, you don't need some fancy framework, plain simple JS will do it. Arguably, it will be even easier to do it in JS than in e.g. Python, because there are tons of examples on the web in case you need to extend the functionality. Occasionally, you will need some visualization (chart or something), but then it's mostly just finding some library and transforming the data into the required format, that's simple enough to do with a language that you are not an expert in. After all, isn't web development already accessible? I would argue that this is the most accessible of software development, with huge amount of high quality, accessible learning resources and various frameworks that enable to develop complex features rather quickly, if needed. True, there's always something that can be improved but I don't think that Python-to-JS solves anything. However, I genuinely believe that a project such as this is a cool side project to explore and improve your software development skills :) so often 'why would you...' can be answered with simply 'because it's fun'.
- threatofrain 11y agoWeb development only moves at fast speeds if you want to adopt the frontier solutions. If you want, you can still use Wordpress or Joomla or whatever, you can still use Bootstrap, you can still use Jquery. These are all optional and have been stable for a decade. A person without interest in web development, such as a scientist who wishes to publish a blog, should be fine with a pre-baked solution like Wordpress. Even if they're comfortable with Python, there's no reason to replicate what "core" Wordpress does, which is no small undertaking. Also, a person working in a field that just happens to use a sprinkle of programming would have to learn a lot of tangential junk just to replicate what pre-baked solutions do, and they would probably do it poorly. It would be better if such individuals just paid for an affordable solution or used something like Wordpress.
- supergreg 11y agoThings like this will totally make sense once they are done in WebAssembly.
- Gladdyu 11y agoAs a general trend with reimplementing stuff in JS, I don't quite know whether this is exciting or horrifying...
- poizan42 11y agoJavaScript may very well have the doubtful honor of being the language that people have spent most resources to avoid writing in.
- hugs 11y agoIt's probably 2nd place. I imagine avoiding writing in C gets the top honor.
- rootlocus 11y agoWhich begs the question: why haven't browsers adopted another scripting language?
- xaduha 11y agoYou can find answer to this easily enough. Some at Google were pushing Dart, read reaction to that from Mozilla, Apple and Microsoft.
- thewhitetulip 11y agoThis will be interesting for codeschool.com and elearning projects, now they can have everything without requiring the backend at all to evaluate the commands that the user sends.
- thegigaraptor 11y agoI wish people would take time to actually learn javascript. I used to see it as a shitty toy language up until 2012. It opened me up to a completely different style of programming.
- gedrap 11y agoI totally agree about actually learning javascript. While the opinion about the language itself is arguable, it's not 2006 anymore. Plain simple JS can get a lot of stuff done nowadays and there's no point to include the whole jquery to hide a dom element or make an ajax request. In addition, understanding the underlying language opens up a lot of doors, compared to just gluing frameworks and jquery extensions together.
- awinter-py 11y agoI saw it as a shitty language until I worked with it full time in 2016 after which I forgot all about clunky syntax and focused on the too-small standard library and web standards nuttiness.
- gaze 11y agoDon't forget the confusing ADHD garbage tooling!
- rubber_duck 11y agoI feel like TypeScript could make JS a decent language if Microsoft starts going more ambitious with it - they really need to do a Dart style integration - official package manager, build system, full es5 transpiler, std lib polyfill included. So far they have been conservative and focused only on typing but they could offer insane value if they started offering a full language expirience like Dart
- ludamad 11y agoIt's an excellent tool. It does make JS a decent language. A package manager is not necessary, it can work with npm. A build system is not necessary, existing build systems support it. I believe they will eventually do full polyfill. However, the compiler is very high quality and that doesn't happen by accident. They have to make hard design decisions to keep releasing features so regularly (they release features faster than I can keep up with sometimes). For now, you can target es6 and chain with babel.
- harunurhan 11y agoBut why?
- harunurhan 11y agoBut why?
- jvilk 11y agoI actually embarked on a similar Python VM called Ninia [1] awhile back, but shelved it as other projects became more important. Ninia supports multiple threads and preempts execution to give the browser breathing space, just like my JVM in JavaScript, DoppioJVM [2]. One of the challenges of Python is its objects are quite complex/ad-hoc, and can be overridden by the user. I mapped out [3] how I wanted to map Python objects to JavaScript objects, but never had the time to implement it fully. (That document covers Python 2.7; I'm sure there are differences for 3.) It looks like this project has a lot of work to do if it wants to have parity with a native Python VM! But that's part of the fun of writing these things. Best of luck on the VM! If you need a file system to plug into the VM for loading modules/implementing the FS API, do check out my BrowserFS library [4], which is currently in use at the Internet Archive [5] and is also used in Ninia/DoppioJVM. You can also cop things from Ninia, as it is MIT licensed. Oh yeah, and if you need a Python compiler/parser, you can simply run the PyPy interpreter's parser+compiler [6] in your intepreter once it is reasonably complete. It is written in 100% Python! [1] https://github.com/plasma-umass/ninia https://github.com/plasma-umass/ninia [2] https://github.com/plasma-umass/doppio https://github.com/plasma-umass/doppio [3] https://github.com/plasma-umass/Ninia/wiki/Mapping-Python-Objects-to-JavaScript-Objects https://github.com/plasma-umass/Ninia/wiki/Mapping-Python-Ob... [4] https://github.com/jvilk/browserfs https://github.com/jvilk/browserfs [5] http://ascii.textfiles.com/archives/4924 http://ascii.textfiles.com/archives/4924 [6] https://pypy.readthedocs.org/en/latest/interpreter.html https://pypy.readthedocs.org/en/latest/interpreter.html
- koehlma 11y agoCool, I will have a look through your code and BrowserFS seems especially useful to me.
- andrewvijay 11y agoGoing through the code and finding new unknown stuffs already!
- koehlma 11y agoOh wow, thanks for the great feedback to all of you!
- foota 11y agoI'd be interested to see how threading support was implemented, seems difficult to do in a browser environment.
- chrisseaton 11y agoIt's easy: you could just run n instructions of thread one, then n instructions of thread two, and so on in a loop. To not freeze up the browser, you could periodically yield to it and set a timeout to start running the next thread again.
- foota 11y agoI guess so. I think I was thinking about concurrently running multiple threads.
- chrisseaton 11y agoThat is already concurrent. Do you mean in parallel? Yeah not easy to do that, you'd have to set up web workers and I think sort of manually recreate the shared state with your own coherence protocol!
- mshenfield 11y agoI think the most salient application for client-side Python (or Ruby) are for companies already entrenched in server side frameworks like Django and Ruby on Rails. For all Django provides, developing in it still feels constrained to a server heavy mid-2000's web development paradigm. While frameworks like React and Ember are pushing the envelope on web applications by allowing you to render HTML apps on the server and on the client, to do something similar in Python means duplicating rendering logic between a server-side template language and a front-end framework like Angular, React, or Backbone/Marionette. Some technologies tackle a part of this problem, like pybars, which allows using Handlebars templates in both a python and javascript process. But it would remove a mountain of mental overhead and code duplication, if feasible, to write an entire web application in Python.
- BuckRogers 11y agoI prefer the web to still be the place where people share HTML documents and do simple data input/retrieval. Rather than shoving a square peg in a round hole. I'm rather happy with the state of Django as a result. I suspect Django Channels will provide all the stateful connectivity most people will need without tossing the baby out with the bathwater. And it's not all roses on the other side either, I've looked into the fullstack solutions that are all JS and promise the world and best future possible but ended up being lackluster in things like SEO.
- coldtea 11y agoI often see this wish expressed (also in here by somebody): >JS engines in browsers should evolve to more general VMs, for which you can implement/port other languages. You do understand that when this happens (and is spread enough to use in production), the web framework and tooling fatigue will be 2-3 times worse. It's not just that everybody and their dog will write their own framework (as now), they'll split even more and do it for 10 languages... And expect the same dilution of effort for libs too... I'd actually prefer a better JS replacement, that is, a new, single, language that draws from it and gets rid of all the caveats fixed (lack of ints, coercion rules, small std lib, optional types, even better designed for high speed JITing etc), than seeing Python, Clojure, Ruby, Lua, PHP and 200 others re-implemented in web assembly...
- pori 11y agoI agree with this assertion. Albeit, isn't this what's to come with WebAssembly?
- ben_jones 11y agoWhere is this "dilution" in the java world? I don't see it.
- coldtea 11y agoThe Java world has 1/10 the programmers Javascript has (which is basically everyone doing web work). The Java world also historically had a parent company giving strong guidance. The Java world also has strong standard libs and tended to include everything and the kitchen sink in them (including full blown servers, XML/XSLT parsers) in the SDK (and EE SDK). Heck, it even has a full JS interpreter there. Even so, there was huge fragmentation of effort for things like web frameworks (Struts, WebWork, Spring, Cocoon, Turbine, Tapestry, and many many more). Actually, if you were doing Java in 2000-2010 it was a running joke how everybody would write their own framework. And I would argue that all the resources diverted to numerous Java-derivative languages (like Kotlin, Ceylon, Xtend, etc) would be better of in making Java better, or creating a single, community driven, Java successor, if there was a process (and access) for that. As it is, they are all doomed to remain niche players, and ultimately fail, while languages like C# and Swift march on.