Mathematics I / Functions and Modularity
Practice question · Multiple choice

A function that reads no globals and changes nothing outside itself is called pure. Why do such functions make a program easier to reason about?

Hints
  1. To predict what an impure function returns, what else do you need to know?
  2. Ask which kind of function can be safely replaced by a lookup table of its past results.
Show the answer

D. Because their behaviour depends only on their arguments

Why

Everything a pure function does is in its arguments, so you can reason about it without holding the rest of the program in your head, and it can be memoised, parallelised or reordered for free. Concentrating side effects at the edges is how large systems stay tractable, whatever the paradigm.

Read the lesson: Functions and Modularity →

Practise Functions and Modularity

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

More questions on Functions and Modularity