Computer Science I / State, Mutation, and Side Effects
Practice question · True or false

A function that writes to a global variable is as easy to test as one that only returns a value, provided both are correct.

Hints
  1. What must a test do before and after the impure one?
  2. Hidden state has to be arranged and restored.
Show the answer

False

Why

False. The pure function needs no fixture and no teardown, and its tests can run in any order. The one touching a global forces every test to set that state up and reset it, and makes tests order-dependent, which is why side effects get pushed to the edges and the middle of a program kept pure.

Read the lesson: State, Mutation, and Side Effects →

Practise State, Mutation, and Side Effects

The app has 7 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on State, Mutation, and Side Effects