Warning: Some posts on this platform may contain adult material intended for mature audiences only. Viewer discretion is advised. By clicking ‘Continue’, you confirm that you are 18 years or older and consent to viewing explicit content.
This is about the same number of lines, but it communicates so much more about the control flow. It gives us an idea which data is involved in the calculations, and where we can find the result of all the calculations. We can make assumptions that the functions inside are independent from each other, and that they’re probably not relying on side effects.
This is also against clean code examples, because Uncle Bob seems to be allergic against function arguments and return values.
This is also against clean code examples, because Uncle Bob seems to be allergic against function arguments and return values.
I think this is your strawman version of “Clean Code”… not anything that’s actually in it…
I “like” some parts of your example more than the previous one, but a lot of this depends on where exactly in the whole program this method is - if this method is on a “Salesman” class - does it make sense to pass the “Contract” in? If there’s a Contract class available, why doesn’t the “calculateCommission” method exist on it?
What I’m saying is that it’s hiding too much of the control flow.
Compare it with this code:
public double calculateCommision(Sale sale, Contract contract) { double defaultCommision = calculateDefaultCommision(sale); double extraCommision = calculateExtraCommision(sale, contract); return defaultCommision + extraCommision; }
This is about the same number of lines, but it communicates so much more about the control flow. It gives us an idea which data is involved in the calculations, and where we can find the result of all the calculations. We can make assumptions that the functions inside are independent from each other, and that they’re probably not relying on side effects.
This is also against clean code examples, because Uncle Bob seems to be allergic against function arguments and return values.
I think this is your strawman version of “Clean Code”… not anything that’s actually in it…
I “like” some parts of your example more than the previous one, but a lot of this depends on where exactly in the whole program this method is - if this method is on a “Salesman” class - does it make sense to pass the “Contract” in? If there’s a Contract class available, why doesn’t the “calculateCommission” method exist on it?
You’re making assumptions about the control flow in a hypothetical piece of code…
Yes, because that’s exactly what the thread is about. Making assumptions about control flow.