microsoft / microsoft/pxt-microbit

Blocks programs w/ variables usually convert to Python programs with "global" keyword everywhere

Open
#3,094 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

python
Dominant language
TypeScript
Stars
804
Forks
721
Avg merge
2d 9h
Merged PRs (30d)
2

Description

Because all variables in blocks are global and we preserve this when converting to TS and then to PY, we end up with a lot of "global" keywords all over the place when converting to Python.

I think this is going to be especially problematic for new users learning Python since the "global" and "nonlocal" keywords are some of the more confusing aspects of the language.

Most cases these global variables should really be converted to local variables when switching to TS or PY. This could be done fairly easily if we did a liveness analysis to determine when it's safe to make variables local.

Here's a simple blocks program that is over complicated when switching to Python:
2020-05-19 11 58 07

I think this will be especially problematic for Arcade since there are more variables used there.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name any files, tests, or entry points. Start by locating the Blocks-to-TypeScript-to-Python conversion path and determine how variable scope is currently preserved; done should mean generated Python avoids unnecessary global declarations while retaining program behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.