Talk:Scorn Globally, Act Locally
From Beautifulcode
Thank you Michael for creating this entry. Let's see if anyone comes here.
I'll get things started.
I think it will be fun and instructional to use an actual example on how to "act locally".
Below a piece of code that you have inherited.
1) What's "wrong" with it, if anything - based on your criteria for code ugliness/beauty?
2) What would you do to this code if you had inherited it and had to maintain it?
public class SalesUtil {
final static double BQ = 10000.0;
final static double BCR = 0.20;
final static double OQM1 = 1.5;
final static double OQM2 = OQM1 * 2;
public static double calculateCommissionDue(double totSales) {
if (totSales <= BQ) {
return totSales * BCR;
} else if (totSales <= BQ * 2){
return
(BQ) * BCR +
(totSales - BQ) * BCR * OQM1;
} else {
return (BQ) * BCR +
(totSales - BQ) * BCR * OQM1 +
(totSales - BQ * 2) * BCR * OQM2;
}
}
}
