Comments (8)
Coincidentally I was looking into this today during my lunch break for something different, one very simple requirement I needed was to be able to use time.sleep()
(as that is one of the first steps in blinking an LED), and after a very brief look around into these three implementations I only found skulpt to work as expected.
This might be related at all to the requirements for this projects, but I though I'd mention it as a simple example of how something we'd think as trivial can be such a deal breaker sometimes.
from coding-with-chrome.
Also! it would be very interesting to identify which one would allow you to step through the code, to be able to do the same type of thing the "JS Interpreter" blockly example does.
from coding-with-chrome.
In general it would not be possible to do the step through the code thing very easily in an Chrome app, because the code is executed in an sandbox (webview).
So the executed code is not able to tell you which is currently executed, nor the UI knows exactly what the sandbox is executing.
from coding-with-chrome.
As far as I can tell all of the above implementations have their upsides and downsides. As I understand it, brython implements Python 3.x while skulpt is most similar to Python 2.2 (while 2.7 is the gold standard at the moment). pypyjs seems to be the most compliant and guess what- the slowest.
Then again, it seems that due to various reasons there is no sleep() equivalent in javascript due to its single threaded nature (source: http://reeborg.ca/docs/en/reference/weakness.html) so indeed implementing it is not as easy as it sounds - although I agree for educational purposes it is important. This thread explains it in more detail: https://groups.google.com/forum/#!topic/brython/UAZADu6Yv_g - but in short it seems to me that the only way to 'emulate' sleep in javascript is to create a loop and breaking out of it after some time. Problem: that shoots the CPU to 100%
Bottom line, I currently see no obvious 'winner' between the implementations themselves, so instead I would suggest looking at them in the meta-level, and picking one based on project activity/maturity, ease of implementing etc. If all that fails... toss a coin?
But yes, I would consider it very valuable to support Python.
from coding-with-chrome.
I just checked Brython and is supports time.sleep as well after "import time".
But as already mention it puts the CPU to 100% so in the worst case the sandbox will kill it.
from coding-with-chrome.
I assume that this killing won't happen after 1 second, so sounds to me it will be fine day-to-day,
from coding-with-chrome.
Since someone mentioned my site and a reply I wrote...
If all that is needed is a "step" method, this can be implemented fairly easily without a sleep() method: all that needs to be done is to record the result of the program (after doing some pre-processing) and play it back. This is what I have done with Reeborg whose documentation is linked in a previous comment. You can see the result with a Blockly integration by going to
http://reeborg.ca/reeborg.html?lang=en&mode=blockly-py
clicking on the "Keep editor visible" checkbox and dragging the editor out of the way. For a demo, I suggest creating a simple program using combinations of "move()" and "turn_left()" functions. When clicking on the "run" button (near the top left), the program will be executed one instruction at a time with the code in the editor being highlighted; the speed of the animation can easily be adjusted (using the "think()" function) and can even be played back forward and backward (the latter available via the additional options menu). Instead of the line of code, one could presumably highlight the block being executed instead. (I may look into doing this "soon".)
A more robust method could likely be implemented using a Python-debugger (https://github.com/amrdraz/python-debugger) designed explicitly to work with Brython; I am simply aware of its existence and have not attempted to use it.
Note that the link to "Reeborg's World" given above is for a newer development version that is incomplete and likely buggy.
from coding-with-chrome.
Thanks for all of your feedback on this, very appreciated.
I just implemented an basic test implemented at the python branch for testing:
https://github.com/google/coding-with-chrome/tree/python
Seems to work fine with generic Python examples.
from coding-with-chrome.
Related Issues (20)
- Open Tasks (refactoring) HOT 2
- importing images in html HOT 1
- Every .cwc file is made by Markus Bordihn
- Every .cwc file is owned by Markus Bordihn
- Update last run version data even if whatsnew feature disabled
- Tile height inconsistent HOT 1
- Joydemo disabled warning should be moved HOT 2
- AIY mode never goes out 'waiting for connection'
- AIY output is very strange to cut/paste
- Advanced > Robots says it is using blockly blocks. It is not
- What's new / Changelog / Version needs to be automated.
- shepherd.js usage HOT 3
- Add a spanish translation HOT 2
- Adding in anoymous tracking
- Editor issues when coding python
- Text across the application doesn't appear correctly when the language changed to other than English HOT 1
- README 404 HOT 2
- input statement not working in Python
- Do we still need "Windows-Build-Tools" to be explicitly installed to run this project?. HOT 1
- Is there a nested git repository inside this project?. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from coding-with-chrome.