Skip to content

Comment on Why Naming Variables Can Distinguish a Good Programmer from a Bad One

Comments

It's not my intention to discard the whole article for this problem but...

   calculateTotalPrice(100, [5, 10, 15]);
And so, a base price of 100 and applying discounts of 5, 10, and 15, produces a total price of... 3000. Odd kind of discount, innit?

I mean, either this is a bad example not well thought out, or the original function is doing something completely different and the supposedly good naming is actually a very bad one since it appears to make sense but doesn't. In either case not good.

Good catch. The total discount should be divided by 100. I missed that. :) Fixed now.

Slow down :)

- In one case you write (p/100) and in the other (totalDiscount/100). It wouldn't matter because the end result is the same mathematically, but the apparent meaning is different. But anyway...

- Now the calculated total price is 30, but it should be 70. totalPrice = basePrice * (1 - totalDiscount/100)

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.