Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Blockly.<language>.variableDB_ to .nameDB_ and add .nameDB_.getUserNames('VARIABLE') and .nameDB_.getUserNames('PROCEDURE') #4845

Merged
merged 13 commits into from
May 28, 2021

Conversation

NeilFraser
Copy link
Contributor

Should be no user-visible changes.

There is significant confusion in names and comments with regards to variables and procedures.  `Blockly.Generator.prototype.variableDB_` is a Blockly.Names database, not a variable map.  This rename introduces a getter and setter so deprecated references still work.  This commit also fixes some comments which are either outright wrong or misleading regarding variable and procedure names.
Also gets rid of hacky name_realm contatination.
Previously isInitialized would remain true after first generation.
Also move common init/finish code to parent class.
Only for JS, Lua, and PHP.  Dart and Python need extra logic to split out import statements.

Also use ‘this’ instead of fully qualified names in generators.
This enables the generator for any block to see all variable names and procedure names in the whole program, including those that haven’t generated yet.
@NeilFraser
Copy link
Contributor Author

The net result of all of these commits is that in any block's generator one can now call either one of:

Blockly.JavaScript.nameDB_.getUserNames('VARIABLE')
Blockly.JavaScript.nameDB_.getUserNames('PROCEDURE')

and get an array of all the user's variable or procedure names.

Comment on lines 414 to 423
Object.defineProperty(Blockly.Generator.prototype, 'variableDB_', {
get: function() {
console.warn('Deprecated use of "variableDB_"; change to "nameDB_"');
return this.nameDB_;
},
set: function(x) {
console.warn('Deprecated use of "variableDB_"; change to "nameDB_"');
this.nameDB_ = x;
}
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a nice way to deprecate something! I'll have to keep this in mind in the future.

Also fix bug in Lua generator where variables were not populated in the nameDB (only language with no variable initialization).
This is potentially dangerous code.  And ID could theoretically collide with a name.
Copy link
Contributor

@maribethb maribethb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was helpful that the cleanup changes were in separate commits, but it'd be even easier to review if they were in separate PRs. This also matters because your PR title will be in the release notes, and having variable and procedure names available on demand might be something devs are interested in seeing at a glance from the notes.

* Getter.
* @deprecated 'variableDB_' was renamed to 'nameDB_' (May 2021).
* @this {Blockly.Generator}
* @return {Blockly.Names} Name database.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new code, we've moved to always providing the nullability modifier (? or !) for non-primitives, to match the current style guide.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed here, and a few dozen other places.

* @return {Blockly.Names} Name database.
*/
get: function() {
console.warn('Deprecated use of "variableDB_"; change to "nameDB_"');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the Blockly.utils.deprecation.warn function, which would be good to use for consistency and so we can more easily track what we have scheduled for deletion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, and changed Blockly.utils.deprecation.warn to also handle properties, not just functions.

Also make Blockly.utils.deprecation.warn apply to properties.
@NeilFraser
Copy link
Contributor Author

It was helpful that the cleanup changes were in separate commits, but it'd be even easier to review if they were in separate PRs. This also matters because your PR title will be in the release notes, and having variable and procedure names available on demand might be something devs are interested in seeing at a glance from the notes.

The flip side is that splitting this into multiple PRs would result in one of:

  1. A set of mostly serial PRs that each block the next and takes much longer
  2. An unmanageable set of merge collisions
  3. Pressure to not fix stuff all over the codebase.

I'm concerned that the current process around release notes is resulting in lower quality code since there's a penalty for resolving side issues on the spot upon discovery. Is there a way we can build informative release notes without discouraging off-topic edits?

@maribethb
Copy link
Contributor

It was helpful that the cleanup changes were in separate commits, but it'd be even easier to review if they were in separate PRs. This also matters because your PR title will be in the release notes, and having variable and procedure names available on demand might be something devs are interested in seeing at a glance from the notes.

The flip side is that splitting this into multiple PRs would result in one of:

  1. A set of mostly serial PRs that each block the next and takes much longer
  2. An unmanageable set of merge collisions
  3. Pressure to not fix stuff all over the codebase.

I'm concerned that the current process around release notes is resulting in lower quality code since there's a penalty for resolving side issues on the spot upon discovery. Is there a way we can build informative release notes without discouraging off-topic edits?

Makes sense. This is one of those times I look longingly over at internal-Google systems and remember how easy it is to have multiple changes going at once. The good ol' days.

I probably would have moved all of the cleanup changes to their own PR, and have a separate PR for the non-cleanup changes around name generation to get that balance between clarity/ease of reviewing and workflow, but I realize everyone sets that threshold differently, so it's not a big deal.

I do think it's a good idea to update the PR title to mention the generator change though, as it's most relevant from a release notes perspective. I'm not sure how best to improve them, since it needs to be an automatic process, and grabbing every commit title is too granular, imo. We could look into it in our next "non-feature week" though! There's probably some tooling out there for it, or we could have a section in the PR template for release notes and parse that out later.

@NeilFraser NeilFraser changed the title Series of independent commits around code generation Rename Blockly.<language>.variableDB_ to .nameDB_ and add .nameDB_.getUserNames('VARIABLE') and .nameDB_.getUserNames('PROCEDURE') May 28, 2021
@NeilFraser NeilFraser merged commit e661c92 into develop May 28, 2021
@NeilFraser NeilFraser deleted the fraser-procedures branch May 28, 2021 04:30
@BeksOmega BeksOmega added the breaking change Used to mark a PR or issue that changes our public APIs. label Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Used to mark a PR or issue that changes our public APIs. component: generators
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants