- Extract Constant
- Extract Variable
All
As a function's expression gains complexity, it is behaviour becomes harder to comprehend. Giving names to intermediate steps of the expression can significantly increase clarity.
Identify groups in the expression which perform a specific task, then store them as values with meaningful names.
(defn order-total
[tax-rate items]
(* (sum (map :amount items)) (+ 1 (/ tax-rate 100))))(defn order-total
[items tax-rate]
(let [tax-multiplier (+ 1 (/ tax-rate 100))
total-amount (sum (map :amount items)))]
(* tax-multiplier total-amount))