Variable Deletions problem

Issue #158 resolved
Turgut Guneysu created an issue

This is related to Issue #143.

I will document it here in a similar manner. But I think the two are related. And I will leave it to you to combine them in any way you see fit.

The problem occurs when one is editing the blocks while the USB connection is in an OFF state.

While the IDE allows deletion of the variables, they are actually (obviously) not removed form the code present in the attached device.

In the stand-alone MB IDE, the deletion process immediately connects the USB port.

However, the IDE does NOT synch the code to the board. Thus the board is running the old code with the deleted variable, and the IDE is displaying the updated code without the deleted variable.

There is no indication of any error at all. If one tries to correct the situation by trying to add the missing var to the IDE version of the code, one gets the dup var treatment of the variable being declared with a 2 attached to the name to make it unique.

Comments (4)

  1. John Maloney repo owner

    Does clicking the “stop” button resolve the broken variable references issue?

    One thing to know is that a variable reference that doesn’t match any global variable will be treated as a local variable even if there is no “local” block for that variable in the script. Do you think that’s what’s happening in this case.

    How can I reproduce this problem?

    Re: If one tries to correct the situation by trying to add the missing var to the IDE version of the code, one gets the dup var treatment of the variable being declared with a 2 attached to the name to make it unique.

    I’m thinking about changing this behavior so that it doesn’t append a “2” since there are times (as you point out) where you are are trying to re-add a global variable that has existing references.

    Background: the intention of the renaming mechanism is to ensure that global variable names are distinct from local variable and parameter names. While lexical scoping has well defined semantics and is the norm in professional languages, it confusing for beginners. In fact, even professional programmers can be confused, which is why some coding standards (including Microsoft’s) use naming conventions to ensure that global variable names are distinct from locals/parameters and immediately recognizable as globals.

  2. Turgut Guneysu reporter

    Does clicking the “stop” button resolve the broken variable references issue?

    No, it does not. IDE allows deletion of VARs regardless of the connection status of the device. In my opinion, given the synch issues, one should NOT be able to edit the code without a device attached.

    One thing to know is that a variable reference that doesn’t match any global variable will be treated as a local variable even if there is no “local” block for that variable in the script. Do you think that’s what’s happening in this case.

    You have to provide that answer, as I have no idea how to verify it. All I can see in the source code is that the variable definition statement is no longer there after the delete, but the references in code to the variable are left intact. This behavior is the same as in SNAP!. However, the difference is: In SNAP, after one deletes a var and then executes the code, any and all references to the variable left in the code PRODUCES A REFERENCE ERROR - NOT SO in MB IDE. If you are saying that there is an implicit LOCAL var assumption in MB, then it should be made visible by declaration of the LOCAL var reference. Having NEITHER that NOR the execution error is what we have at this moment.

    How can I reproduce this problem?

    Very easily:

    • Make a var
    • Make some blocks that refer to that var.
    • disconnect / disable the USB connection.
    • delete the var in IDE
    • Then we are at what I am describing.

    I’m thinking about changing this behavior so that it doesn’t append a “2” since there are times (as you point out) where you are are trying to re-add a global variable that has existing references.

    I believe this will make all the visible issues kind of GO AWAY ! but needs to be paired with the EXECUTION ERROR on every reference to the missing var in the program - and NOT A LOCAL assumption !

    That way the user gets ERRORS when a var is deleted but has references - which can be corrected by adding it back in globally or locally. Or all the var references needs to extracted from the code, which will be possible with the help of the ERROR messages.

  3. John Maloney repo owner

    It's a fairly deep assumption in MicroBlocks that any variable that isn't global is assumed to be local. The error you want would be a compilation error, not a run-time error and, like Scratch, MicroBlocks made the design choice to not have any concept of compilation error. It does the best it can to make sense out of the user's script and, in this case, that means interpreting any non-global variable reference as if the variable was local to the script.

  4. Log in to comment