Code copied from one project to another may not work

Issue #143 resolved
Turgut Guneysu created an issue

Same issue in both stand-alone and Browser version:

Any way to make this a true error and not skip ?

It is confusing since the copy / paste of custom blocks do not work correctly and DO NOT give any error messages either.

Combined with this “in the background” behavior one has to figure out why one set of code that worked in one environment all of a sudden does not work when copied in another with the same devices.

The only way to figure things out is by peeking into the Command window or Console display in dev mode - not something newbees will do.

Comments (5)

  1. John Maloney repo owner

    I believe the issue is that the project is missing the WiFi library. Will think about ways to make this more clear to the user.

    Do you think it would be better to remove the code copy/paste feature given that the copied code doesn’t bring along all the libraries, variables, and user-defined functions it depends on? A different way to handle this would be allow the user to merge one project into another. That would bring along all the necessary context but might then require a lot of work to delete the parts one didn’t want…

  2. Turgut Guneysu reporter

    OK, this is going to be a bit longwinded:

    VARIABLES:

    I believe there is a disconnect between the source blocks and the running version of the program as it pertains to the variables.

    The PASTED copy of a code, while it does NOT contain the variables, still runs correctly. This is probably because there are variable references in the running code that do not require a var definition, per se ! (This is my presumption / assumption based on looking at the code fragments saved and loaded).

    Hence, the code referencing the vars runs OK. However, trying to declare the missing var ends up with a var2 copy of the original var name, since the IDE finds the reference in the running code, doesn’t allow a dup creation, and creates a #2 version of the same name var.
    To me, this is bit wacky: because the missing var is NOT visible in the source as a definition, but does exist in reference while running it, and works. Additionally, one cannot DELETE such a var reference, yet cannot add another one with the same name to correct the DEFINITION issue.

    FIX: The var definition logic must be looking at the occurrences of the var name in code, to allow / disallow duplicates ! Should it not look at the variables declarations in the source ? This would eliminate the dup declaration problem and allow one to correct the situation.
    Also, similar to the missing LIBRARY issue, the variable block in the program could be RECOLORED to alert the user to missing var definition.
    Or, since program knows about the mismatch, it could just add the missing variables declarations.

    LIBRARIES:

    The issue with the libraries is a bit different: the color of the missing library is changed to a lighter color of the original. I did not notice this originally, since it is a very subtle change until one notices it ! I like the concept, since it is very easy to bring in missing libraries.
    FIX: I would prefer a more OBVIOUS color scheme: red, bright orange, or yellow to draw attention to it right away; and these do not occur amongst the normal blocks.
    Or even a message display alerting the user to the missing elements.

    SUMMARY:

    I believe there is merit to copy / paste if one writes code that is lengthy and needs to reference previously written code. As such, given the above issues are addressed, it would be a benefit to have it in the IDE.

    Alternatively, if the changes to correct are cumbersome or not worth the effort, then maybe the copy/paste can be an OPTION to be turned on and off by the user, while being aware of the caveats and how to work around them.

    I hope this was helpful, with the exception of my assumptions ! 🤔

  3. John Maloney repo owner

    The variables issues described here will be fixed in 1.0.1. Feel free to submit a new issue for the unreferenced function issue (i.e. displaying calls to missing functions in a different color).

  4. Log in to comment