Skip to content

Why mutability ? #377

@cyrilchapon

Description

@cyrilchapon

Coming from non-game environments (FP inspired Javascript notably, like well known flux architecture or even react at its core); I was heavily surprised the philosophy of State update has mutation at its core.

To challenge that, asking here a naive but important question :

Why not taking a non-mutative approach ?
ie

  onTick(prevState: InternalState, ctx: Context, timeDelta: number): InternalState {
    return {
      ...prevState,
      testValue: 1
    }
  }

instead of

  onTick(state: InternalState, ctx: Context, timeDelta: number): void {
    state.testValue = 1
  }

IMHO, this approach is broadly proven to be more easily testable and determinism-friendly

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