Skip to content

The "effects" system is not consistently used #1920

@mythmon

Description

@mythmon

In a thread on another repo I said "[effects in Framework] aren't well understood or universally used". At @Fil's prompting, I wanted to expand on that.

In #39 we implemented the first version of the authentication process. It required reading and writing from files, remote APIs, and stdio. This made it hard to test without also dealing with a lot of state and making our test output very noisy. To try and make this easier to test, I drew on an idea from functional programming: algebraic effects.

JavaScript doesn't support algebraic effects, so I faked it by supplying various functions with an extra last parameter that provided a library of functions it could take. These were intended to be used for all "impure" behaviors: file operations, stdio, API calls, etc. By doing this, the test suite could provide an alternate version of the effects that didn't interact with the real resources, such as a having an in-memory file system or by feeding in an array of lines to "stdin". This helped make the tests quieter and easier to write, though it did make some code (the code in the effects) difficult or impossible to test.

Overtime, code was written that performed these "effectful" operations, but didn't use effects. For example, in the deploy process there is an effects object, but we directly read files to calculate their hashes. Reading files which should be an effect by the intent I explained above.

framework/src/deploy.ts

Lines 586 to 591 in 82412a4

const fullPath = join(this.deployOptions.config.output, path);
const statInfo = await stat(fullPath);
const hash = createHash("sha512")
.update(await readFile(fullPath))
.digest("base64");
manifestFileInfo.push({path, size: statInfo.size, hash});

Other parts of the code directly write to stdout, write to files, and perform other actions that interact with the environment without using effects, even when an effect object is in use in the same function. Here's an example in the CI output of output of the test being printed to stdout instead of being captured like the effect system says it should be.

From this I concluded that I did not properly embed the idea of effects into the code and explain it to the people working on Framework. That's ok.

I'm not arguing for or against effects in this issue. I wanted to explain the problem that I see. I think it would be reasonable to remove the effects system entirely. It would also be reasonable to work to extend effects to cover more of the code. I think the most prudent approach is probably to leave this as is, and keep this in mind in future code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions