Neat trick for code testing

Suppose you have a function, and you think of a different approach that might be better, but you need to test it. You don’t want to mess up the function you have, so you first create a copy with a different name, to keep it safe, and then mess with the code.

There’s a neater way to do this, if you do it a lot. Create an extra tab on the right called (say) “Test”. Make a copy of your function in there (keep the name the same). Mess with the code. Run it. When Codea compiles your code (from left to right), it will compile both copies of the function, but the Test copy will overwrite the original function because its tab is to the right and gets compiled later, so it will be used instead.

This enables you simply to put copy any function into your Test tab and play with it, then delete it when you’re done, keeping your original code very clean.

you could copy the function just down below the original and have the same effect., since the compilation goes from top to bottom inside the document…

True! As long as you don’t get confused and edit the wrong one! Which is the sort of thing I have done before when I have two versions too close together.

also true)))

Nice, this is good to know. I just ran into this problem about an hour ago when editing my auto-tile algorithm. I totally butchered my original function and thought I screwed myself, but good thing I had a complete copy saved in emails, hehe.

Nice tip, I’ve never considered doing that.