Say it like this
- Keep the function pure
- This is a pure function, so it's easy to test
- We need more pure functions in this module
Use it at work
Code review
- Make this a pure function so it's easy to test.
- This isn't pure. It changes a global variable.
Explaining
- A pure function always gives the same output for the same input.
- Pure functions have no side effects.
Design
- Keep the logic pure and put side effects at the edges.
- Reducers should be pure functions.
Don't say this
Purity is about behavior and predictability, not code appearance or simplicity.
Don't mix it up
| Term | What it is | Who writes or uses it | When |
|---|---|---|---|
| pure function | Same input, same output, no side effects | Developers | Logic, tests |
| side effect | Change outside the function | Developers | I/O, state |
Practice
Try it
4 quick exercises
1. This function modifies a global variable, so it is not a _______ function.
2. Which sentence uses pure function incorrectly?
3. Your colleague asks about improving testability. How do you respond?
4. Rewrite this using pure function language: The add function takes two numbers and gives back their sum without changing anything else.
Say it out loud
Phrase 1 of 3
"Keep the function pure"
We don't save your recording. The word check uses your browser's speech recognition.
More about pure function
Real examples(3)
- in a code review
"This function modifies the user object directly. We should make it pure by returning a new object instead."
- in a team meeting
"Pure functions help us avoid bugs because they don't depend on hidden state or side effects."
- in a standup
"I refactored the calculation logic into pure functions so the tests run much faster now."
More mistakes(2)
Handle with care. Do not confuse with mathematical purity or cleanliness of code. Pure functions are specifically about predictability and side effects.
- ✕We pure-functioned the code yesterday.✓We refactored the code into pure functions yesterday.
Pure function is a noun that describes a type of function, not a verb for refactoring code.
- ✕This pure function reads from the database and updates the cache.✓This function reads from the database and updates the cache, so it's not pure.
Functions with side effects like database reads or cache updates are impure by definition.
Other forms(2)
- pure function noun
"A pure function never modifies external state."
- pure adjective
"We should write pure code whenever possible."
Often used with(5)
- write a pure function · Create or implement a pure function in your code
- keep functions pure · Maintain the purity property when designing functions
- pure function returns · Emphasize what a pure function outputs based solely on inputs
- side effects · Pure functions have no side effects; they do not modify external state
- predictable output · Pure functions produce consistent, predictable results
Similar words(2)
- deterministic function · Similar concept emphasizing that output depends only on input, but less commonly used in modern tech
- function without side effects · A more descriptive phrase meaning the same thing, but longer
Opposites(2)
- impure function
- function with side effects
Questions(5)
- What does pure function mean in software engineering?
- A pure function is a function that always produces the same output for the same input and does not modify any external state. It has no side effects, such as changing global variables, modifying files, or making API calls. This makes pure functions predictable and easy to test.
- How do you use pure function in a sentence at work?
- You can use it like: We should refactor this logic into pure functions to improve testability. Or: This function is not pure because it reads from a database. Or in a meeting: Pure functions help us avoid bugs.
- Why are pure functions important in programming?
- Pure functions are important because they are easy to test, reason about, and debug. They do not depend on hidden state or global variables, so they behave consistently. Teams often prefer pure functions because they reduce bugs and make code maintenance easier.
- What is the difference between a pure function and an impure function?
- A pure function always returns the same output for the same input and has no side effects. An impure function may return different outputs for the same input or may modify external state, such as changing a database or global variable.
- Is pure function formal or informal?
- Pure function is a neutral, technical term used in both formal documentation and casual conversations at tech companies. It is appropriate in code reviews, meetings, technical documentation, and interviews.



