Why a 10% discount can't go first: rule order in pricing
transcript
A rental price. Daily rate, weekend surcharge, long rental discount, one-way fee. One big function with nested ifs? Then the next rule edits all of them.
Each rule is a small class. It gets the request and the running subtotal. It returns labelled lines. The engine adds them up. A new rule is a new class. Nothing else is edited.
Why does the long rental discount come after the others? It takes ten percent of the subtotal. Run it first, and the subtotal is only the base. It discounts less. So the order lives in one list, with a test. Order is part of the design.
A week of SUV at ninety a day, plus weekend, is six sixty-six. Ten percent off is sixty-six sixty. Then a fifty dollar one-way fee. Total: six forty-nine forty. All in integer cents.
Price as a pipeline. Mind the order. Use integer cents.
Full breakdown in the lecture.