Functions as single source (fee copy-paste)
Spot diverging copy-pasted fee logic, explain the risk, and prove a single-function fix on a fresh variant.
REAL PROBLEM: The same platform fee is calculated in three screens — checkout web, POS tablet, and invoice PDF. Each screen pasted its own formula. After a promo tweak, one screen still uses the old percent. Customers see different fees for the same cart. WHY this matters: Pricing trust breaks when the rule lives in multiple places. Support tickets explode; finance cannot reconcile; one "quick fix" silently creates a second truth. The bug is not a single wrong number — it is duplicated behavior that can diverge. HOW it usually happens: A developer copies fee = subtotal * 0.05 into three files. Later someone changes only one. Tests that only hit one path never see the drift. There is no single function that owns "what is the fee for this cart?" GUIDED QUESTIONS: How many places encode the fee rule today? What happens when only one is updated? What should call sites pass in, and what should one function return? CONCEPT: Functions exist so one behavior has one home. Extract calculateFee(cart) (or calculatePlatformFee(subtotal, policy)) and call it from every surface. Policy changes then update one place; screens stay consistent. Duplication is a liability until it is a single source of behavior.
Key takeaways
- WHY this matters: Pricing trust breaks when the rule lives in multiple places.
- HOW it usually happens: A developer copies fee = subtotal * 0.05 into three files.
- GUIDED QUESTIONS: How many places encode the fee rule today?
Sign in to complete activities, save progress, and use the AI Coach.
Evergreen instructional material; no time-sensitive claims to source.
Evergreen curriculum written from KleinHub teaching material — no time-sensitive claims.
AI-generated lesson, reviewed by Education Review and approved through the KleinHub approval queue before publication.
Sign in to complete this lesson, track progress, and use the AI Coach.
Sign in to start lessonCreate account