Small Steps

Here is a pattern for a bad programming decision:

While we are doing X let's save some time and do Y too.

The correct way to do this:

Do X first. After that works do Y.

Programming is much harder and much riskier than normal life. Through making normal life decisions we get hard-wired to be efficient in ways that kill us in programming.

For example if you are going out to mail some bills and you realize you also need some milk it makes sense to do the two things together instead of make two separate trips. This is because mailing bills and buying milk are simple tasks that do not contain as much risk as making a code change.

But now let's say you are going to rob a bank and then as you are leaving your house to go to the bank you realize you also need some milk. In this case it is probably a bad idea to combine the two errands together. Robbing a bank is a high risk activity. If you stop on the way to buy milk you are likely to fail in both tasks.

So in high-risk ventures it is better to violate common sense (where it suggests to combine tasks together to save time) and to serialize the tasks as much as possible. Don't refactor common elements of high-risk tasks.

It sounds to me in programming you need to finish one task completely before beginning another task -- Andrea.

One might argue that you examples are not entirely precise. Shopping and buying two items instead of buying one after the other rather struck this code in my mind:

WalkToMall()
BuyBread()
WalkHome()
WalkToMall()
BuyMilk()
WalkHome()
This is just some Lock/Unlock-procedure and you can turn this into:
WalkToMall()
BuyBread()
BuyMilk()
WalkHome()

Your second example can be explained with this, too:
WalkToBank()
RobBank()
WalkHome()
WalkToMall()
BuyMilk()
WalkHome()
HEre you can see that is requires knowledge about the interactions of RobBank() and WalkToMall(), and probably a function WalkFromBankToMall() in order to get just one WalkHome().

A better example might be cooking dinner while cleaning the frying pan.

Besides that, I agree.


This seems to contradict the advice in MakeTheSmallestChangeThatCouldPossiblyWork.


CategorySuccess


EditText of this page (last edited February 27, 2011) or FindPage with title or text search