google / blockly

The web-based visual programming editor.
https://developers.google.com/blockly/
Apache License 2.0
12.25k stars 3.64k forks source link

Improve readability and maintainability of undo method #8167

Open TridentGalaxy opened 1 month ago

TridentGalaxy commented 1 month ago

Check for duplicates

Problem

The Workspace.undo() method takes one bool parameter named "redo" which, if false, performs the undo action as one would expect of an "undo()" method, and if true, performs a redo of the last action that was reverted using undo(). Since the name of the parameter is not visible when calling the method (e.g. undo(false)), this seems unintuitive and decreases readability and maintainability of Blockly code. See Blockly reference.

To fix

  1. In core/workspace.ts, find the undo method and give it a default value of false

This will allow users to simply call undo() to undo something, while still allowing undo(true) to redo.

If you'd like to work on this issue, please comment here so we can assign it to you. You can also read our contributing docs

Alternatives considered

Alternatives considered

No response

Additional context

No response

maribethb commented 1 month ago

Hi, thanks for the issue.

Making the parameter optional so that if you don't pass a boolean we'll default to false is reasonable. Your other suggestions might be a bit too heavyweight. Also, it's common for folks to annotate single parameters like this with a comment so that it's clear to future readers, e.g. undo( /* redo */ false)

TridentGalaxy commented 3 weeks ago

Thanks for the positive feedback. :)

If you follow Clean Code guidelines, comments like undo( /* redo */ false) should not be necessary. The method names should be clear enough.

Therefore, I would still suggest to add a redo() method that internally just calls undo(true), even if the solution with the performUndoRedo() method won't be implemented.

Thank you for considering my suggestion.