logoalt Hacker News

lscharentoday at 5:06 PM2 repliesview on HN

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;

Replies

metabageltoday at 5:28 PM

OK, or maybe...

  total = calculateOrderTotal(user.order);
  total = total * user.discount;
show 1 reply
Narishmatoday at 5:51 PM

Didn't you just shift the branch to the calculateDiscount() function?

show 1 reply