4 ms·
Maybe something (contrived) like this providing no-op defaults? total = calculateOrderTotal(user.order); if (user.isPremiumMember) { total = total * 0.
by lscharen 16d ago
Maybe something (contrived) like this providing no-op defaults?
total = calculateOrderTotal(user.order);
if (user.isPremiumMember) {
total = total * 0.9; // 10% discount
versus
total = calculateOrderTotal(user.order);
discount = calculateDiscount(user); // Returns 0.9 or 1.0
total = total * discount;
- metabagel 16d agoOK, or maybe... total = calculateOrderTotal(user.order); total = total * user.discount;
- 1718627440 16d agoOr: total = calculateOrderTotal(user.order); total *= user.discount; or: return calculateOrderTotal(user.order) * user.discount;
- Narishma 16d agoDidn't you just shift the branch to the calculateDiscount() function?
- 1718627440 16d agoNot necessarily. return 1 - user.isPremiumMember * 0.1; would also cut it.
- lscharen 14d agoNo, because the point is that the branch version does not touch "total" when the branch is taken, but the non-branch version will always multiply "total" by something.