Pure functions
Objectives :
Understand what are Pure Functions and the benefits of using them
Connection - 10'
Categorize these code samples in Pure Functions vs Impure Functions :
Explain your choices.
Concept - 5'
Pure functions don’t refer to any global state. Those functions do not produce any side effects (state changes).
They are easier to test because of these properties:
You can see all the inputs in the argument list
The execution is deterministic (the same inputs will always get the same outputs)
You can see all the outputs in the return value
Code that is harder to test will lack some or all of these properties.
Concrete Practice - 30'
Clone the repository here
Identify the design problems related to the RentalCalculator
Refactor this code by using Pure Functions
A step by step solution is provided in the solution branch (Look at the commits)
Conclusion - 10'
How much of the time do you find yourself writing tests for functions that have all the three properties of pure functions ?
What do you need to write more Pure Functions ?
Last updated