I have been building a few classroom activities with Computation Layer and I am trying to keep my scripts easier to read and reuse. I would love to hear what habits made the biggest difference for others.
Here is what has helped me so far:
Name components clearly - descriptive names make scripts far easier to follow later.
Start from a small working screen - adding one feature at a time keeps bugs easy to find.
Comment tricky logic - a short note saves time when revisiting an activity.
Test as a student - previewing in student view catches confusing steps early.
Reuse proven patterns - copying a screen that already works beats rebuilding from scratch.
Keep feedback specific - short targeted messages help students more than long ones.
Check on different devices - layouts that look fine on a laptop can break on a tablet.
What Computation Layer habit made the biggest difference for you, and is there anything you wish you had started doing sooner?
Thanks for starting this. A few I’d add to your list:
Put each screen’s logic in one place. The button does the checking and keeps track of the round and the streak, and the other components just read from it.
Seed randomGenerator with the button’s pressCount, so every press gives a new problem.
Wrap any value you interpolate into an expression in parentheses. Without them, a negative value turns into things like -77–77, which evaluates to undefined.
Use numbers (0 and 1) for flags instead of true and false.
On reusing proven patterns, I kept one running document of the CL patterns that worked in my activities, and it ended up as the knowledge base behind CL for Desmos & Amplify, a free ChatGPT plugin. You describe the activity in plain language, and it writes the CL and says where each piece goes.
As for your last question, I wish I’d had it sooner. Building by hand took me a long time, I had to limit what I built to what I knew how to code, and a bigger activity took proportionally longer. Now I can picture what I want a screen to do and just make a screen that does it, and more complicated activities don’t take much more time than simple ones. What I’d have used it for most is the kind of thing above: problems randomly generated within well-defined constraints, and answer tracking with rounds and streaks. It does both well and quickly for pretty much any problem type.
It isn’t perfect, so I’d still test as a student, like your point 4. You can find it by searching “desmos” in ChatGPT’s plugin library. It’s my own project, not affiliated with Amplify or Desmos.
I agree with most but have a caveat with the first:
Depending on how detailed you mean by “clearly”, I find naming components simply (e.g. button, choice, input, graph) is often sufficient and makes reusing screens or individual components much easier. I’d only opt for more descriptive when referencing components from other screens. You also don’t need to name components at all if they’re not being referenced by others.
I would add, define any components you’re referencing with variables at the top of your code. If you end up needing to rename a component, it’s orders faster to change that referenced component at the top instead of finding all the individual references. AND, use this to refer to a component you’re in rather than its name. Again reduces editing.
b = button
g = graph
time = b.timeSincePress()
slope = g.number(`m_1`)
Similarly, anything that is reused should have a definition. We use time in multiple places for various purposes in the curriculum and, maybe not perceptibly, it improves performance. I also like to define the conditions used for sinks (e.g. isCorrect to use for the correct: sink), which can help with debugging when you have issues.
Try to limit how much you send in and out of a graph. You shouldn’t, for example, have a value in CL that you send into a graph to perform a calculation (and may also be needed for an animation or feedback), which is then sent back to CL to be utilized. The calculation should just be made in CL.
@Aaron_Veek I’m going to disagree with this one. I will always put code for validation in the component where answers are placed, and any references that are needed elsewhere can be pulled specifically. It makes it much easier to piece components together in a new screen. But agree that tracking info belongs in the button.
Try to order your code by dependency. If you have a line of code above a variable it’s dependent on, you can get a lot of false error warnings as you’re editing/refining (and some of the autocomplete won’t pop up!).
On validation, I can see the advantage of keeping it in the input when you want to reuse components on a new screen. In my practice activities the button also makes each new problem (a randomGenerator seeded with its pressCount) and moves the round and the streak along, so I’ve kept the check there too, to keep everything that depends on the current problem in one place. Agreed that the tracking belongs in the button either way.