forresto / turtle-svg

JavaScript turtle graphics to SVG for laser cutting = LASER TURTLES!!!
http://forresto.github.com/turtle-svg/
26 stars 8 forks source link

Variable persistence considered harmful. #15

Closed craftoid closed 11 years ago

craftoid commented 11 years ago

Problem

If a variable is defined in the editor and definition is removed later, the variable is still defined.

This should not be the case, because the result of the program would depend on hidden variables, which will not be defined next time the program is reloaded or shared, resulting in runtime failure.

Scenario

Create a simple program

 var s = 10;
 f(s);

Play with it, removing the variable definition, but still use it somewhere in the code. The program still runs without complaint.

 f(s);

Now share the code with your mom. Program fails, mom cries, chaos ensues.

Solution

Restart / reset the worker every time before running the code.

forresto commented 11 years ago

Hmm yes, good point. I think it isn't expensive to terminate the worker, so might as well spin it up for every eval.

craftoid commented 11 years ago

:+1:

forresto commented 11 years ago

This is also good if somebody evals moveForward = turnLeft = turnRight = null; or something on accident. I can't think of a way to protect those functions (and also keep the eval simple)...

forresto commented 11 years ago

Tested with

moveForward = null; // FAIL

then

// moveForward = null; // OK