OpenFn / kit

The bits & pieces that make OpenFn work. (diagrammer, cli, compiler, runtime, runtime manager, logger, etc.)
12 stars 11 forks source link

Lazy state: Maybe remove $ #780

Open josephjclark opened 2 months ago

josephjclark commented 2 months ago

Lazy state is proving a bit hard for people (even people on the team) to understand

The story for new users is:

Use $ to access state

Cool, but then they open up a callback and it breaks. So now the rule is:

Use $ to access state, unless in a callback

Which I suppose isn't too bad, but does require a certain mindfulness.

Why don't we drop $ entirely and just treat state as a special entity in the compiler? All the rules we apply to $ now just apply to the special variable state. Which means: if we see state passed into an operation at the top level, we wrap it up in a lazy function.

Reasons for:

Reasons against:

I'm warming to the idea that we go ahead and do this. I think we do still need to document something about what's happening, especially if users look at their compiled code. But it would be heavy advanced stuff.

josephjclark commented 1 month ago

We can remove a lot of docs by doing this you know. We just need an expandable box saying something like "when you reference state at the top level, it will always be lazily evaluated. Here's what the compiler does to your code".