Skip to content

The meaning of side effects 🤔  #2

Open
@skyrpex

Description

@skyrpex

I think the current definition of side effects is incorrect:

A function is considered to have side effects if it performs any action other than returning a value. Side effects include, but are not limited to, modifying variables or objects, reading or writing to files, making network requests, and interacting with the DOM.

I believe the above description suits pure more than side effects. A function can have no side effects even if it reads external data such as files or variables from outer scopes. On the other hand, it would cause side effects if the function wrote to a file or modified variable from outer scopes (note that modifying variables created in its own scope still doesn't count as having side effects).

Although, I understand that even reading a JS variable may cause a side effect in certain situations (for example, when using a proxy). Network requests, even GET requests, may cause side effects too (eg, a page view counter that increases for each visit). Finally, reading files may cause the OS to update some file descriptors or whatever... But still, is it safe to assume that most of the time, those operations shouldn't count as side effects?

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